saunj657
saunj657

Reputation: 5

Call to a member function createQueryForType() on null - exception

I followed Creating a first extension but I'm getting 500 error and:

[Tue Mar 14 09:45:42 2017] [warn] mod_fcgid: stderr: PHP Fatal error:
Call to a member function createQueryForType() on null in /var/typo3_src/typo3_src-6.2.29/typo3/sysext/extbase/Classes/Persistence/Repository.php on line 251

Server PHP 5.6 and Typo3 6.2.29

Repository code:

<?php
namespace MyVendor\MyExt\Domain\Repository;

use \TYPO3\CMS\Extbase\Persistence\Repository;

class UserRepository extends Repository {
    public function __construct() {
    }
}

Controller action:

public function getOnlineUsersAction() {
    $userRepository = GeneralUtility::makeInstance(UserRepository::class);
    $users = $userRepository->findAll();
    // todo
}

Upvotes: 0

Views: 2059

Answers (2)

cweiske
cweiske

Reputation: 31078

In TYPO3 v12 I had this problem when creating a repository instance from another model object via GeneralUtility::makeInstance() and using methods on that repo.

The solution was to make the repository public in Configuration/Services.yaml.

Upvotes: 3

Thomas L&#246;ffler
Thomas L&#246;ffler

Reputation: 6164

Try:

Repository code:

<?php
namespace MyVendor\MyExt\Domain\Repository;

use \TYPO3\CMS\Extbase\Persistence\Repository;

class UserRepository extends Repository {
    // Remove the __construct (or add parent::__construct)
}

Controller code:

/**
 * @var MyVendor\MyExt\Domain\Repository\UserRepository
 * @inject
 */
$protected $userRepository;

public function getOnlineUsersAction() {
    $users = $this->userRepository->findAll();
    // todo
}

Upvotes: 1

Related Questions