【问题标题】:Typo3 Extension Scheduler Command ControllerTypo3 扩展调度程序命令控制器
【发布时间】: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!!!这意味着,NewsRepositoryfindAll() 函数根本不起作用!!!

相比之下,我还在普通的控制器类中使用了这个 NewsRepositoryVendor\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


    【解决方案1】:

    答案是简单:您需要在 CommandController 中为您的新闻记录定义 storagePid 将 NewsRepository 的设置更改为 IGNORE storagePid。

    如何为 CommandController 设置 storagePid: https://worksonmymachine.org/blog/commandcontroller-and-storagepid

    如何设置仓库忽略 storagePid: http://typo3.sascha-ende.de/docs/development/database/how-to-ignore-the-page-id-pid-in-repository-database-query/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      相关资源
      最近更新 更多