在 null 上调用成员函数 createQueryForType() - 异常

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

我关注了 Creating a first extension 但我收到 500 错误并且:

[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

服务器 PHP 5.6 和 Typo3 6.2.29

存储库代码:

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

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

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

控制器动作:

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

尝试:

存储库代码:

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

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

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

控制器代码:

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

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