Is it possible to do an aftersave() on an app_controller.php in CakePHP?
I want to detect this on the app_controller for global use so I won't redo it on each controller or model.
Thanks, S
Is it possible to do an aftersave() on an app_controller.php in CakePHP?
I want to detect this on the app_controller for global use so I won't redo it on each controller or model.
Thanks, S
firstly afterSave()
is function of cake's model class not controller. So recommended solution is to define a general /app/app_model.php
// app/app_model.php
class AppModel extends Model {
function afterSave($created) {
if($created) {
// do clean up after insert
} else {
// do clean up after update
}
}
}
In your model class
// app/models/user.php
class UserModel extends AppModel // <- its extending AppModel
This will be executed by all request by $this->ModelName->save()