[TYPO3-mvc] ItemsRepository: Fatal error: Call to a member function createQuery()
Anja Leichsenring
aleichsenring at ab-softlab.de
Tue Jun 24 14:42:40 CEST 2014
Sorry, forgot one:
On 24.06.2014 14:40, Anja Leichsenring wrote:
> Hi Muriel,
>
> the functionality belongs without doubt to the repository, but you made
> an error:
>
> > class ItemsRepository extends \TYPO3\CMS\Extbase\Persistence
> \Repository {
> >
> > /**
> > * Find top 5
> > *
> > * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
> > */
> > public function findTop5() {
> > $query = $this->itemsRepository->createQuery();
>
> $query = $this->createQuery();
>
> > $query->matching($query->equals('top5', 1));
> > $query->setLimit(5);
> > $query->execute();
> >
> > return $query;
needs to be
$result = $query->execute();
return $result;
> > }
> > }
>
> createQuery() is a method of the RepositoryClass you extend.
>
> Hope this helps?
> Kind regards
> Anja
>
>
>
> On 24.06.2014 14:31, Muriel le Pair wrote:
>> Hi,
>>
>> My ItemsRepository looks like this:
>>
>> class ItemsRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
>>
>> /**
>> * Find top 5
>> *
>> * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
>> */
>> public function findTop5() {
>> $query = $this->itemsRepository->createQuery();
>> $query->matching($query->equals('top5', 1));
>> $query->setLimit(5);
>> $query->execute();
>>
>> return $query;
>> }
>> }
>>
>> When I run the code below, I get a Fatal error: Call to a member
>> function createQuery()
>>
>> class ItemsController extends
>> \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
>> /**
>> * action listTop5
>> *
>> * @return void
>> */
>> public function listTop5Action() {
>> $itemss = $this->itemsRepository->findTop5();
>> $this->view->assign('itemss', $itemss);
>> }
>> }
>>
>> But when I insert the code directly to the ItemsController it works fine.
>>
>> class ItemsController extends
>> \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
>>
>> /**
>> * action listTop5
>> *
>> * @return void
>> */
>> public function listTop5Action() {
>>
>> $query = $this->itemsRepository->createQuery();
>> $query->matching($query->equals('top5', 1));
>> $query->setLimit(5);
>> $itemss = $query->execute();
>>
>> }
>> }
>>
>> The odd thing is that it works in another extension.
>> So what am I doing wrong?
>>
>> --
>> kind regards,
>>
>> Muriel le Pair
>
More information about the TYPO3-project-typo3v4mvc
mailing list