检测 CakePHP 的 AppController 的 afterFilter 方法中的插入/更新/删除
我在 CakePHP 应用程序中添加了一些代码到我的 AppController
(/app/app_controller.php
) 的 afterFilter()
方法中我正在发展。此代码重建一个大型静态文件,我只想在插入、更新或删除记录时产生重建的开销。除了在执行更新的每个控制器的操作中设置某种标志之外,是否有一种方法可以检测数据库在请求期间是否已被修改?
I have some code I've added to the afterFilter()
method of my AppController
(/app/app_controller.php
) in a CakePHP app I'm developing. This code rebuilds a large, static file and I only want to incur the overhead of that rebuild when a record has been inserted, updated, or deleted. Apart from setting some sort of flag in every controller's actions that perform an update, is there a way to detect whether the database has been modified during a request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在模型中(app_model,如果你想为每个模型使用它),你可以使用 afterSave 函数可以在您执行 save/saveAll 时使用它,这通常是您在蛋糕中创建/uodate 时使用的。
当您删除某些内容时,您还可以使用 afterDelete 方法 来执行此操作。
希望这对你有帮助:)
In the model (app_model if you want it for every model) you may use afterSave function you may use it just when you do a save/saveAll that normally is what you use to create/uodate in cake.
Also you have the afterDelete method to do it when you delete something.
hope this helps you :)