I am trying to include a small code in each page of my site.
Is there any way to do this without modifying each controller?
For example – I want to read/unread message from Message model.
Can i do this using the app_controller? I have add following function in app_controller.php.
I need suggestion. Please help me.
function messageStatus() {
App::import('Model','Message');
$new_message = $this->Message->find(
'first',
array (
'conditions' => array (
'Message.status' => '1'
)
)
);
$this->set("new_message",$new_message);
}
Depending on when you want to execute your actions, you will have to override in the
app_controller.phpfile one of the following functions (according to the documentation), :Since all your other controllers will be inheriting the methods of this class, your actions will be executed every time (as specified in the docs) one of your controllers are executed.
If you want to have a controller that does not run the code in the
app_controllersimply override the method again locally.