Search code examples
databasecakephpcontrollerdetection

Detecting insert/update/delete in CakePHP's AppController's afterFilter method


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?


Solution

  • 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 :)