phpcodeignitercodeigniter-3

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.


Solution

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