检测 CakePHP 的 AppController 的 afterFilter 方法中的插入/更新/删除

发布于 2024-12-16 12:19:34 字数 227 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨凡馨 2024-12-23 12:19:34

在模型中(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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文