Call controller method within library without redirect - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Call controller method within library without redirect (/showthread.php?tid=68145) |
Call controller method within library without redirect - Russ_AB - 06-01-2017 Hey! I'm building a library for CI and I need to run the callback after my logic. How do i call a controller method within library? I tried different ways and nothing worked PHP Code: $default_controller_callback = 'Welcome'; Here is the full library code: https://github.com/russ-ab/CodeIgniter-Custom-Exception-Handler/blob/master/libraries/Custom_Exception.php#L192 I want to change the redirect to real callback calling. Thanks! RE: Call controller method within library without redirect - PaulD - 06-01-2017 I have not looked at your full code (sorry) but I believe you cannot do what you ask (ie call controller method from somewhere else) without HMVC or similar. (I am not 100% on this though) However there is no reason why your callback in, say, controller A, cannot call a common function (say 'common_callback_function') from a model or a library to get a result, just like any library or model call works. It is just a function after all. Then you are free to reuse that common_callback_function in any other library, or from where ever you want. Keeping everything DRY. I hope that makes sense. Paul. |