Welcome Guest, Not a member yet? Register   Sign In
accessing other controller methods
#1

Hi,

Please any one can tell me how to access the methods of one controller ito another controller methods without Extends
Reply
#2

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
Reply
#3

(03-25-2015, 05:06 AM)[email protected] Wrote: Hi,

Please any one can tell me how to access the methods of one controller ito another controller methods without Extends

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.
Reply
#4

Or use a library as suggested earlier. You can use it in as many controllers as you need.
Reply
#5

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB