Typo3 accessing an existing table to consume data of it

天涯浪子 提交于 2020-01-06 06:01:34

问题


I tried to integrate an existing table to my extension. The problem is that the content of the table isn't taken over. I created a new model with the name of the existing table and named the properties according to the existing column names. I also implemented the corresponding getters and setters of the properties.

The name of the existing table is tx_institutsseminarverwaltung_domain_model_event.

What is my failure in this case? Just want to access the data of an existing table from another extension.

Thanks in advance.

UPDATE:

I tried this:

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

and 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);
}

But no results returned.


回答1:


You should use the repository linked to this table. Something like this :

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



回答2:


How are you trying to "consume" or access the data from the other table in your extension?

Do you have a repository for the existing table (maybe there is already an existing repository, that you can reuse)?

See german typo3 board mapping existing tables and SO thread TYPO3 / How to make repository from existing table fe_users?




回答3:


solution is:

    $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);


来源:https://stackoverflow.com/questions/49380221/typo3-accessing-an-existing-table-to-consume-data-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!