CakePHP: calling function in the AppController
You don't. Models and/or behaviors should not talk back to the controller. If the method is so universally usable, make it a function in bootstrap.php
, put it in AppModel
if it's applicable there or create your own utility class in /app/libs
that you can call statically from anywhere.
(You can call AppController::myMethod()
anywhere, provided you're in a normal request cycle where the AppController
is already loaded, or use ClassRegistry::init
to get an instance of any controller (which will have the method), but this'll probably create more problems than it solves. Don't do this.)
Related videos on Youtube
Harsha M V
I turn ideas into companies. Specifically, I like to solve big problems that can positively impact millions of people through software. I am currently focusing all of my time on my company, Skreem, where we are disrupting the ways marketers can leverage micro-influencers to tell the Brand’s stories to their audience. People do not buy goods and services. They buy relations, stories, and magic. Introducing technology with the power of human voice to maximize your brand communication. Follow me on Twitter: @harshamv You can contact me at -- harsha [at] skreem [dot] io
Updated on June 04, 2022Comments
-
Harsha M V almost 2 years
How to call a function inside the app_controller.php in app/app_controller.php in the behavior of a plugin which is at app/plugins/media/models/behaviors/transfer.php inside a method called transferTo.
-
JohnP about 13 yearsYou shouldn't be calling your app controller from a behavior in the first place. If you really must have access to your controller, then use a component
-
-
Marwan Salim over 5 yearsrequestAction() is depreciated since CakePHP 3.4, please use other solutions such as View Cell. Following is the link to study View Cell [sanisoft.com/blog/2014/09/15/view-cell-cakephp-3-quick-start/]