TYPO3 存储库-> 添加不起作用 [英] TYPO3 repository->add not works

查看:25
本文介绍了TYPO3 存储库-> 添加不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 TYPO3 版本 7.6.18

I have TYPO3 version 7.6.18

$newMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Istar\\Femessages\\Domain\\Model\\Message');
                $newMessage->setUserFrom($myUid);
                $newMessage->setUserTo($userTo);
                $newMessage->setChainUid($messageChainUid);
                $newMessage->setMessage($message);
                $this->messageRepository->add($newMessage);
                $persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
                $persistenceManager->persistAll();

没有

            $persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
            $persistenceManager->persistAll();

请告诉我,为什么?

推荐答案

Extbase 的持久性管理器启动,当请求完成并且您的操作完成时呈现视图并响应请求.这是设计使然,也是为什么存储库只存储它必须更新或插入您提供给它的对象而不是实际执行的操作.

The persistence manager of Extbase kicks in, when the request is being finished and your action is done with rendering the view and answering the request. This is by design and why the repository just stores that it has to update or insert the object you are giving to it instead of actually doing it.

这种方法与延迟加载有关,您只需在真正需要时加载数据.查看您的对象,当您请求它们时,存储库会将您发送回去.如果您使用像 xDebug 这样的调试器检查结果,您会注意到结果实际上不包含任何您请求的对象,它只是您的查询的表示.仅在您需要时才会获取数据,例如,如果您在此 QueryResult 对象上调用 toArray.

This approach has to do with lazy loading, where you just load data, when you really need it. Have a look at your objects, the repository sends you back, when you request them. If you inspect the result with a debugger like xDebug, you will notice that the result actually does not contain any of your requested objects, it is just a representation of your Query. The data will be fetched only if you need it, say if you call toArray on this QueryResult object.

数据持久化也是如此.系统假定您不需要立即保留数据,因此它会等待将数据发送到数据库,直到完成对请求的所有处理.通过这种方式,可以使用较少的数据库连接来包含数据,反过来也可以节省时间.

The same is done for data persistence. The system assumes that you don't need the data persisted right away, so it waits with sending the data to the database until all processing of the request has been done. This way the data can be included with less database connections and this in return will save time.

如果在添加对象后确实需要持久化对象,则需要像您描述的那样调用 PersistenceManager.这可能是,如果您想生成一个指向您的新的、尚不存在的对象的链接.

If you really need to persist objects after you added them, you need to call the PersistenceManager like you described. This could be, if you want to generate a link to your new, not yet existing, object.

请记住,persistAll 方法会执行它所说的操作,它将保留对所有存储库的所有对象的所有更改,直到执行该点.据我所知,没有办法只持久化一个特定的对象,至少到目前为止是这样.

Keep in mind that the persistAll Method does what it says, it will persist ALL changes to ALL objects given to ALL repositories until that point of execution. There is no way of persisting just one specific object, at least up until now, that I know of.

这篇关于TYPO3 存储库-> 添加不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆