Skip to content
Advertisement

Calling AppModel function in AppController for cakephp

I have a function that I want all of my controllers to be able to use, so I have defined it in AppController. Now part of what this function will do has no business being in a controller and so it should be in a model, but since this is a universal operation, it only seems correct that it be in AppModel. My function looks as followed:

JavaScript

I simply want to be able to call an AppModel function from AppController. I have tried the following:

JavaScript

But this then complains about the lack of database table called AppModel, at which point, in AppModel I tried setting:

JavaScript

But that blows the whole app up so… Now I am out of ideas. Any help would be greatly appreciated.

Advertisement

Answer

All your models should inherit from AppModel, so why not call $this->AnyModel->get_some_cool_data($term); instead? AppModel should be pretty much be an abstract class anyways — you pretty much never want to instantiate it, you just use as a base class.

Also, that should be $useTable = false; not $usesTable. Remember that, again, all your models should inherit from AppModel, so all your models will end up not using the database as well, which is probably the source of your errors.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement