accessing other controller methods |
Hi,
Please any one can tell me how to access the methods of one controller ito another controller methods without Extends
I think you can't access a controller method in another controller in CI. but you can do it define a library.
1. create MyFunctions.php in to application/libraries folder. <?php /*MyFunction.php*/ defined( 'BASEPATH' ) or exit( 'No direct script access allowed' ); class MyFunctions { public function __construct( $config = array() ) { // initialize } public function function1() { // your code here } } 2. setting autoload.php in application/config folder to auto load your library. $autoload['libraries'] = array('database', 'email', 'session', 'MyFunctions', 'table', 'upload' ); 3. call your methods everywhere. $this->myfunctions->function1(); thats it.
rk128
(03-25-2015, 05:06 AM)[email protected] Wrote: Hi, Hi, What you want is HMVC, meaning Hierarchical Model-View-Controller. Codeigniter will not do that out of the box, but you can always install a third-party HMVC extension, like the one Wiredesigns has on their bitbucket: https://bitbucket.org/wiredesignz/codeig...sions-hmvc. Then all you have to do is add modules::run('controller_name/method_name', $params_array) inside your controller.
Or use a library as suggested earlier. You can use it in as many controllers as you need.
Just try to separate what "Use" means in your case..
Usually Controller methods are used as Actions and they care about some special request.. For usage you usually need some library , model or something as that.. Best VPS Hosting : Digital Ocean
|
Welcome Guest, Not a member yet? Register Sign In |