Upendra Sharma
Upendra Sharma

Reputation: 685

How to call a controller from another controller in codeigniter?

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.

Upvotes: 3

Views: 9986

Answers (2)

kunal ghosh
kunal ghosh

Reputation: 1

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();

Upvotes: 0

Abdulla Nilam
Abdulla Nilam

Reputation: 38672

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()

Upvotes: 3

Related Questions