Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: how to use a model in the app_controller

Iv got a method in a model that I want to be executed everytime a page is requested so I think I need to call it from the app_controller but can't seem to get it to work. The model i want to use is called Blacklist and it has a method in it called check_blacklist() which is what I want to run every time a page is requested. Does anyone know how I should do it?

Thanks

like image 613
geoffs3310 Avatar asked Dec 31 '25 09:12

geoffs3310


1 Answers

Well, one way to do that would be adding:

var $uses = array('Blacklist');

In your AppController class.

Perhaps a better solution is using a CakePHP built-in method called: loadModel, like this:

$this->loadModel('Blacklist');

If you add Blacklist in the $uses array in your AppController, it will be available in all of your controllers, loadModel just loads the Model for a specific task.

like image 50
pawelmysior Avatar answered Jan 02 '26 08:01

pawelmysior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!