3
votes

I'm unable to run the FindBy magic function property in Extbase MVC

    $title=array(0 =>'Books Day');

    $each_event=$this->eventRepository->findByTitle($title);

$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .

How do I make this work?

I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(

I'm using TYPO3 6.1 and extension builder.

3
Is the problem still exists?András Ottó

3 Answers

3
votes

The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?

The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:

$foo = $query->execute()->toArray();

By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:

$result = $this->myRepository->findAll();
0
votes

Try

$each_event=$this->eventRepository->findByTitle($title)->toArray();

Reference to the QueryResult.

0
votes

As said in the documentation, it returns a QueryResultInterface|array.

As a consequence you have to loop over the result like this:

foreach($each_event as $single_event) {
    $single_event->getProperty();
}

If you are sure that it returns only one single value you could also access it by the index 0:

$each_event[0]->getProperty();