We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 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...


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


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 ?