【发布时间】:2018-06-06 11:17:18
【问题描述】:
这是我在TYPO3扩展开发中遇到的一个问题。
我写了一个 TYPO3 扩展。它将在浏览器中显示数据库中的新闻。但我想配置一个调度程序任务来定期更新要显示的数据库中的新闻。
在编写此调度程序任务时,我使用了命令控制器。
namespace Vendor\Extension\Command;
class CheckNewsCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
public function simpleCommand()
{
$newsRepository = $this->objectManager->get( \Vendor\Extension\Domain\Repository\NewsRepository::class );
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($newsRepository);
$all_news = $newsRepository->findAll();
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($all_news);
}
}
但是变量$all_news什么都不包含,它等于NULL!!!这意味着,NewsRepository 的 findAll() 函数根本不起作用!!!
相比之下,我还在普通的控制器类中使用了这个 NewsRepository:Vendor\Extension\Controller\NewsController
namespace Vendor\Extension\Controller;
class NewsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function listAction()
{
$newsRepository = $this->objectManager->get( \Etagen\EtSocNewsSt\Domain\Repository\NewsRepository::class );
$all_news = $newsRepository->findAll();
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($all_news);
}
而且,在 NewsController 中,函数 NewsRepository::findAll() 确实有效,并返回了数据库中的所有记录。
那么,谁能告诉我,为什么 Repository 函数将仅在类 Vendor\Extension\Controller\NewsController 中工作,但 不能 > 在 Vendor\Extension\Command\CheckNewsCommandController 类中工作?
【问题讨论】:
标签: command typo3 task scheduler