Common functions in CodeIgniter

别等时光非礼了梦想. 提交于 2019-12-02 15:24:00

问题


I am new to CodeIgniter.

I am using HMVC in CodeIgniter and want to use a module function in many other modules:

e.g I have a Locaton_model with function get_locations($param) { return; }

How do I use the above function in many other modules? Should I load the model in other module controllers every time I need this function or define the function some where globally?


回答1:


You can easily achieve that by using core controllers: http://ellislab.com/codeigniter/user-guide/general/core_classes.html

Instead of beginning your model with:

class Some_model extends CI_Model {}

You start with:

class Some_model extends MY_Model {}

Edit: It is also possible to use libraries: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

This is useful when you want more general things, like a search engine, a IMAP interface, that kind of stuff.




回答2:


if your creating your own model first make sure it is inside the core folder second on your controller extends the model name like this

class myController extends Locaton_model {

function index()
{
$this->load->model->("your model name");
$this->yourmodelname->functionname($param);
}

}



来源:https://stackoverflow.com/questions/24886716/common-functions-in-codeigniter

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