How to call a controller from another controller in codeigniter?

风格不统一 提交于 2020-02-24 11:33:08

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/32943717/how-to-call-a-controller-from-another-controller-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!