Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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...



11.2k

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



55.9k
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 ?