We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Call controller method from another controller

I have a method in one controller, and I need to run it also from another controller. can I Call controller method from another controller ?

or how would you make it? maybe register that method as external lib or smth...



27.0k

I think you will wirte you function in library, then use it by $this->class->function();



85.5k
Accepted
answer

pff i am dumb again damn it.

inside your controllers folder, create BaseController, and every other controller will extend this base controller, so then you can have common functions between the controllers.

edited Nov '15

Well tbh in controllers only public methods which should be in controllers are actions, you can have some private methods to do some stuff with response/request/view etc inside controller. But base controllers are mostly for calling some action in (almost)ALL controllers, not just a few. If you want to call the same method in few controllers maybe this method should go to some service ?