Felix
Felix

Reputation: 5629

Extbase Query doesn't work

I want to get an object from a repository of my extension.

I added the following code in the Controller FachController

/**
* modulRepository
*
* @var \ReRe\Rere\Domain\Repository\ModulRepository
* @inject
*/
protected $modulRepository = NULL;

And I try to get the Object like this:

$modulUID = $this->request->getArgument('modul');
$modul = $this->modulRepository->findByUid($modulUID);

but I get an Error in this line:

$modul = $this->modulRepository->findByUid($modulUID);`

Error is:

Call to a member function findByUid() on a non-object

Why do I get this error?

In my repository, i've added this code:

public function findByUid($uid) {
  $query = $this->createQuery();
  $query->matching($query->equals('uid', $uid));
  $models = $query->execute();
  return $models;
}

Upvotes: 0

Views: 1272

Answers (1)

lorenz
lorenz

Reputation: 4558

You don't need to have a findByUid method in your repository because this method is already defined in the Repository base class.

The problem is most likely that you didn't clear the system caches (in Development Context, there's a button for this in the Backend and there's a button for it in the Install Tool) after adding the dependency injection for the $modulRepository. This is necessary because the dependency injection is cached and this cache is not flushed on clearing the general cache.

Upvotes: 3

Related Questions