Typo3 Instance Exception - typo3

Why i'm getting this Exception?
Argument 1 passed to KRT\KrtJobs\Domain\Model\Jobs::setPlaces() must
be an instance of KRT\KrtJobs\Domain\Model\Places, string given,
called in
/var/www/html/Newwebsite/typo3conf/ext/krt_jobs/Classes/Controller/JobsController.php
on line 96
This is my code in the controller
if($arguments['jobSave']){
$addJobsInfo = GeneralUtility::makeInstance('KRT\\krtJobs\\Domain\\Model\\Jobs');
$addJobsInfo->setJobtitle($arguments['jobDesignation']);
$addJobsInfo->setCompany($arguments['jobCompany']);
$addJobsInfo->setPlaces($arguments['jobPlace']);
$this->jobsRepository->add($addJobsInfo);
$persistenceManager = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
$persistenceManager->persistAll();
}
This is my Model
/**
* Sets the Places
*
* #param \KRT\krtJobs\Domain\Model\Places $places
* #return void
*/
public function setPlaces(\KRT\krtJobs\Domain\Model\Places $places)
{
$this->places = $places;
}
I'm Getting error on this
$addJobsInfo->setPlaces($arguments['jobPlace']);
I want to insert the data into jobs Database but the places are called from another table. So when I'm trying to insert I'm getting the above exception.
I'm using typo3 version 7
Is there a solution?

You have to load an Instance of Places and set this, error says you cant set strings.
$places = $this->placesRepository->findByName($arguments['jobPlace']);
$job->setPlaces($places):
or something like this... and you should always use Domain Models in singular eg. "Place".

Related

Virtual properties in TYPO3 extbase domain models?

I'm trying to use a virtual domain model property in TYPO3 9.5.x that doesn't have a database field representation but I can't get it to work.
My model looks like this
class Project extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* participants
*
* #var string
*/
protected $participants;
...
/**
* Returns the participants
*
* #return string $participants
*/
public function getParticipants()
{
$this->participants = "foo";
return $this->participants;
}
}
I do see the property when I debug the model but it's always null as if it doesn't even recognise the getter method getParticipants().
Any idea what I might be doing wrong?
Already added a database field to ext_tables.sql and the TCA, but it didn't seem to make a difference.
The property is null because that's the state when the Extbase debugger inspects it. Notice that the Extbase debugger knows nothing about getters and also does not call them.
So if you want to initialize your property you must do this at the declaration time:
protected $participants = 'foo';
You can debug this property by simpy accessing it.
In Fluid, if you use <f:debug>{myModel}</f:debug>, you will see NULL for your property.
But if you directly use <f:debug>{myModel.participants}</f:debug>, you will see 'foo'.

PHP strict_types and relation to invisible TYPO3-record

A property of the model is a relation to one other record like this:
/**
* #var \MyCompany\MyExtension\Domain\Model\OtherObject
*/
public $otherObject;
/**
* #return OtherObject
*/
public function getOtherObject(): OtherObject
{
return $this->otherObject;
}
Now, assume the connected object to be invisible (e.g. it's hidden or time-restricted). Extbase is trying to assign 0, but PHP expects an instance of OtherObject... Bam! - you get an error.
How to deal with that? Hidden or time-restricted records are not uncommon.
You either need to require PHP 7.1 and use a nullable return type hint like ?OtherObject or remove the type hint completely for now. In any case you cannot rely on something being returned here so your consuming code needs to handle this.

Fileupload TYPO3 getting null on findAll()

Hi have a backend module extension to upload files. Im using helhum fileupload for reference. File upload is successful. But the file filed of table updates the uid of sys_file_reference instead of no of files. Why it happens?
<f:form.upload property="file" />
my reference is this Where can I set the table name and no_files in my table and sys_file reference
The property "file" I assume is an 1:1 relation which is why the UID of the file reference is what gets written in to the field.
Had the property been a M:N or 1:N table you would see the number of files, as you expect - and Extbase would need to know you want an ObjectStorage containing FileReference objects on your property.
Regarding the subject, if your Repository returns NULL when you do findAll, this is almost always because of storage page restrictions. To overcome it, override either createQuery and manipulate QuerySettings on the query before it gets returned, setting respectStoragePageUids(false).
I got the solution for my problem. my model was
/**
* Sets the file
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
* #return void
*/
public function setFile(\TYPO3\CMS\Extbase\Domain\Model\FileReference $file = NULL)
{
$this->file = $file;
}
I removed the type from argument list .Now its working fine.My updated code is below
/**
* Sets the file
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
* #return void
*/
public function setFile($file = NULL)
{
$this->file = $file;
}

Flexform Hook of tx_news not working in TYPO3 8.x

In my Extension I'm using the backendUtility Hook of the tx_news Extension. It works well in previos versions of TYPO3.
/**
* #param array|string $params
* #param array $reference
* #return void
*/
public function updateFlexforms(&$params, &$reference) {
if ($params['selectedView'] === 'News->calendar') {
$removedFields = $this->removedFieldsInCalendarView;
$this->deleteFromStructure($dataStructure, $removedFields);
}
}
In TYPO3 8.3 and 8.4 I got the following warning:
1: PHP Warning: Declaration of \Foo\BarBackendUtility::updateFlexforms(&$params, &$reference) should be compatible with GeorgRinger\News\Hooks\BackendUtility::updateFlexforms(array &$dataStructure, array $row) in /path/to/BackendUtility.php line 0
As it is a hook and it needs these parameters params and reference, I can not change it to the parameters of the original function. This would also lead to an issue.
What am I missing here?
Just rename your updateFlexform method to a different name.
Problem is because of php7
The first answer and the comment in the same thread (both by Georg Ringer) combined leads to the solution:
/**
* #param array $params
* #param array $reference
* #return void
*/
public function updateFlexformsDatedNews(&$params, &$reference) {
if ($params['selectedView'] === 'News->calendar') {
$removedFields = $this->removedFieldsInCalendarView;
$this->deleteFromStructure($params['dataStructure'], $removedFields);
}
}
This works with PHP5.6 and 7.0
This is PHP Warrnig message, Becaue in TYPO3 8 core updateFlexforms() function pass two parameters with always type array. You need to pass array value in this function.

SphinxQL & Phalcon\Mvc\Model

I have a Sphinx search engine running on MySQL protocol and I use Phalcon\Db\Adapter\Pdo\Mysql to connect to it. Sphinx tables are implemented as models.
When I try to select (using SpinxQL) I, obviously, get an error when database adapter attempts to extract table metadata running queries against tables which are not supported and not present respectively in SpinxQL. There is a workaround in the documentation showing how to manually assign metadata... But being to lazy by nature I want to try to automate metadata generation.
I assume that metadata is produced by the database adapter, probably as a result of calling getColumnsList() on the instance following getColumnDefinition() or something else (???). Is this my assumption correct? I want is to extend Phalcon\Db\Adapter\Pdo\Mysql and override those methods to be compatible with Sphinx.
Thanks in advance for your suggestions!
Ok, you need to override at least two methods to make this work, the following class would work:
<?php
class SphinxQlAdapter extends Phalcon\Db\Adapter\Pdo\Mysql implements Phalcon\Db\AdapterInterface
{
/**
* This method checks if a table exists
*
* #param string $table
* #param string $schema
* #return boolean
*/
public function tableExists($table, $schema=null)
{
}
/**
* This method describe the table's columns returning an array of
* Phalcon\Db\Column
*
* #param string $table
* #param string $schema
* #return Phalcon\Db\ColumnInterface[]
*/
public function describeColumns($table, $schema=null)
{
}
}
Then in your connection, you use the new adapter:
$di->set('db', function(){
return new SphinxQlAdapter(
//...
);
});