简体   繁体   English

TYPO3 extbase-获取非持久对象的“ uid”

[英]TYPO3 extbase - get “uid” of non persisted object

Just started out with the frst extbase extension. 刚开始使用第一个extbase扩展。 In localconf I added these actions: 'list, new, show, create, edit'. 在localconf中,我添加了以下操作:“列出,新建,显示,创建,编辑”。

Default was that "create" redirected to "list" with no arguments, and that worked fine right after creation of the extension. 默认为“创建”重定向到“列表”,不带任何参数,并且在创建扩展名后立即运行良好。

$this->redirect('list'); // <- this works if used

But instead of redirecting to "list" I would like to redirect to "show" to display the newly added priceFormCalc. 但是,我不想重定向到“列表”,而是重定向到“显示”以显示新添加的priceFormCalc。 A collegue helped me to acomplish this using persist. 一位同事帮助我使用persist来完成此任务。

Below is the code and it works. 下面是代码,它可以工作。 But reading on the net it seem that it should not be best practice to run persist. 但是,在网上阅读看来,坚持下去不是最佳实践。 It should be doable to call the action show without manually persisting first. 无需先手动坚持就可以调用动作表演。

So question is: Is this the correct way to do it, or is there a more "ext base" way show a newly created record? 因此,问题是:这是正确的方法吗?还是显示新创建的记录的更“扩展基础”方法?

public function createAction(\TYPO3\OgNovomatrixpricecalc\Domain\Model\PriceCalcForm $newPriceCalcForm) {
    $this->priceCalcFormRepository->add($newPriceCalcForm);
    $this->flashMessageContainer->add('Your new PriceCalcForm was created.');

    // workaround - or the right way?
    $persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Persistence_Manager');
    $persistenceManager->persistAll(); // <- save i database
    $uid = $newPriceCalcForm->getUid(); // <- get UID of newly saved record

    // do redirect using uid of newly created priceCalcForm
    $this->redirect('show',Null,Null, array('priceCalcForm' => $uid));
}

To

You can persist the current state and then get the uid. 您可以保留当前状态,然后获取uid。 Inject the configuration manager (TYPO3 6.x way): 注入配置管理器(以TYPO3 6.x方式):

/**
 * persistence manager
 *
 * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
 * @inject
 */
protected $persistenceManager;

Then use 然后使用

$this->persistenceManager->persistAll();

to apply all changes. 应用所有更改。 Then you can pass your object (or only the uid) to the action. 然后,您可以将对象(或仅uid)传递给操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM