Search code examples
phptypo3extbasetypo3-7.6.x

Fatal error: Call to a member function findAll() on null in TYPO3


I want to get the objects of a repository but I have next error

Call to a member function findAll() on null

The error line is $projects = $this->projectRepository->findAll();

First used the object manager to get the repository, it did not work. The current configuration is: In Controller

/**
 *projectRepository
 *
 * @var \VENDOR\MyExtName\Domain\Repository\ProjectRepository
 * @inject
 */
protected $projectRepository = null;

And Repository

class ProjectRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
  public function createQuery() {
    $query = parent::createQuery();
    $query->getQuerySettings()->setRespectStoragePage(FALSE);
    return $query;
  }
}

This happens also with findByUid($uid)

The objects exists in DB and visible in BE.

I cleaned the caches, deleted the contents of the typo3temp directory and followed the questions about a similar error (that I thought) Call to a member function findAll() on a non-object , but it did not work and the exception I have is different.

I appreciate your help, please guide me to correct this error


Solution

  • This error is almost always caused by the annotation "compiling" of extbase and related to the cache. You said you cleared the caches and removed the contents of typo3temp, but the cache clearing methods are very different and they do not work for every cache.

    For example, the annotation cache is only cleared by using the Clear Cache button of the Install Tool. The toolbar icons on top of the TYPO3 backend do not clear these kinds of caches.

    The annotation caches will not get stored in the typo3temp folder afaik, but have their own section in the database. Cache clearing should NEVER be done by deleting typo3temp folder content by hand, but ALWAYS via the Install Tool or the appropriate buttons or commands in the TYPO3 backend or the CLI.

    Finally, there is an autoload cache of PHP classes, that doesn't get cleared by the Install Tool either. So if you add a new PHP class to your extension in development, you need to deinstall and reinstall your extension via the extensionmanager. If you are using composer to install your TYPO3 instance, it is again a little bit different. If this is the case, you can clear the autoload cache by typing in the command composer dump-autoload to clear the class loading cache of composer, since TYPO3 is using it if in composer mode.

    I guess that you simply did not try the Install Tool button to clear the cache.