在扩展中按标题查找页面

find page by title in extension

在我的扩展程序中,我想按标题查找页面。 我试试:

/**
 * PageRepository
 *
 * @var \TYPO3\CMS\Frontend\Page\PageRepository
 * @inject
 */
protected $pageRepository = NULL;

然后

$this->pageRepository->findByTitle('my title');

我收到错误:

Oops, an error occurred: Call to undefined method TYPO3\CMS\Frontend\Page\PageRepository::findByTitle()

如何按标题查找页面?

pageRepository 未提供方法 findByTitle()。您可以使用 getPage() 页面 Uid 的方法,如下所示。

$this->pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
$page = $this->pageRepository->getPage($pageId, false);

getRecordsByField() \TYPO3\CMS\Frontend\Page\PageRepository class returns 页面记录数组的方法。

您需要将页面标题传递给方法的第三个参数,如下所示。

$pagesArr = $this->pageRepository->getRecordsByField('pages', 'title', 'my title');

Here is the documentation about the : PageRepository Class Reference https://api.typo3.org/typo3cms/current/html/class_t_y_p_o3_1_1_c_m_s_1_1_frontend_1_1_page_1_1_page_repository.html#a7943e29e2820497d6e30b1414120075e