How to access function from every controller in codeigniter

回眸只為那壹抹淺笑 提交于 2020-01-15 06:18:27

问题


Hi friends hi have this function in one controller , how can i access it from every other controller ?pls help

public function click_add($ads_id){
    //some statement here
    redirect($ads_site['url']);
}

回答1:


There are a few possibilities:

  • Define a helper
  • Create a parent controller class from which all other controllers in your application extend
  • Create a library
  • Use ModularExtensions to allow calling one controller inside another

It all depends on what exactly the function should do. If it shouldn't access the model, then you could go for the first three options. Otherwise I'd suggest the latter two.




回答2:


One solution would be to create your own library.



来源:https://stackoverflow.com/questions/7553912/how-to-access-function-from-every-controller-in-codeigniter

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