3

I want to load a controller function from another controller function using codeigniter. What is the suitable way to do this so when call it url should be changed also.

Upendra Sharma
  • 575
  • 2
  • 9
  • 28
  • Check [this](http://stackoverflow.com/questions/14165895/how-to-load-a-controller-from-another-controller-in-codeigniter). – Deepak Biswal Oct 05 '15 at 08:04
  • You can not do that with standard codeigniter you need a third party add on called HMVC. https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc –  Oct 05 '15 at 08:12
  • basically this is not how MVC functions if you want to call one controller to another then your code requires refactoring – Linus Oct 05 '15 at 09:06

2 Answers2

3

No You cant do it.

What you have to do it is create that function in model and call it through your controllers. So it will work fine.

Ex

In Model

function get_id()
{
   //some argument 
}

In controller 1

$this->Model_name->get_id()

In controller 2

$this->Model_name->get_id()
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

yes you can (for version 2)

load like this below inside your controller

$this->load->library('../controllers/whathever');

and call the following method:

$this->whathever->functioname();