简体   繁体   中英

Call controller function within another controller in Codeigniter

I am trying to call a function Commanfuntion in controller Return_test which is located in the Assign_test controller.

Example:

class Assign_test extends REST_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function Commanfuntion()
    {
     //code
    }
}

class Return_test extends REST_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function Return()
    {
     //here I want to call Commanfuntion located in class Assign_test
    }
}

As Codeigniter follows the MVC pattern you can't call a controller function in another controller. However you can do this by using a function helper and call the function from function helper in any controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM