Typo3 Extension Scheduler 命令控制器
Typo3 Extension Scheduler Command Controller
这里是我在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 !!!这意味着 findAll() NewsRepository 的函数根本不起作用!!!
相比之下,我还在普通控制器中使用了这个 NewsRepository Class: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 函数 ONLY 在 class Vendor\Extension\Controller\NewsController[=38= 中工作], 但 NOT 在 class Vendor\Extension\Command\CheckNewsCommandController ?
中工作
答案是简单:您需要在CommandController 中为您的新闻记录定义storagePid 或 更改NewsRepository 的设置忽略 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/
这里是我在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 !!!这意味着 findAll() NewsRepository 的函数根本不起作用!!!
相比之下,我还在普通控制器中使用了这个 NewsRepository Class: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 函数 ONLY 在 class Vendor\Extension\Controller\NewsController[=38= 中工作], 但 NOT 在 class Vendor\Extension\Command\CheckNewsCommandController ?
中工作答案是简单:您需要在CommandController 中为您的新闻记录定义storagePid 或 更改NewsRepository 的设置忽略 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/