Typo3访问现有表以使用它的数据

时间:2018-03-20 09:15:15

标签: typo3 typo3-6.2.x typo3-7.6.x typo3-extensions

我尝试将现有表格集成到我的扩展程序中。问题是表的内容没有被接管。我创建了一个具有现有表名称的新模型,并根据现有列名称命名了属性。我还实现了属性的相应getter和setter。

enter image description here

现有表格的名称为tx_institutsseminarverwaltung_domain_model_event.

在这种情况下我的失败是什么?只想从另一个扩展中访问现有表的数据。

提前致谢。

更新

我试过了:

/**
 * Protected Variable objectManager wird mit NULL initialisiert.
 *
 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
 * @inject
 */
protected $objectManager = NULL;

和listAction():

/**
 * action list
 *
 * @return void
 */
public function listAction() {
    echo "test";
    $theRepository = $this->objectManager->get('\TYPO3\institutsseminarverwaltung\Domain\Repository\EventRepository');
    $yourRecords = $theRepository->findAll();
    $this->view->assign('events', $yourRecords);
}

但没有结果返回。

3 个答案:

答案 0 :(得分:1)

您应该使用链接到此表的存储库。像这样:

$theRepository = $this->objectManager->get(\Your\VendorName\Domain\Repository\TheRepository::class);
$yourRecords = $theRepository->findAll();

答案 1 :(得分:1)

您是如何尝试“使用”或访问扩展程序中其他表中的数据?

您是否拥有现有表的存储库(可能已存在可以重用的现有存储库)?

请参阅german typo3 board mapping existing tablesSO thread TYPO3 / How to make repository from existing table fe_users?

答案 2 :(得分:0)

解决方案是:

    $querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
    $querySettings->setRespectStoragePage(FALSE);

    $theRepository = $this->objectManager->get('TYPO3\\institutsseminarverwaltung\\Domain\\Repository\\EventRepository');
    $theRepository->setDefaultQuerySettings($querySettings);

    $yourRecords = $theRepository->findAll();
    $this->view->assign('events', $yourRecords);