我想编写一个函数来加载辅助文件中的下拉列表,因此我想在Helper文件中使用我的模型.
当我使用它时,它给我错误:
$this->load->model("news_model");
错误:
Fatal error: Using $this when not in object context in C:\xampp\test\application\helpers\component_helper.php on line 6
我的方法:
function dropdown($Class,$Attribute) { $Output=NULL; $ClassName=$Class."_model"; $this->load->model($ClassName); $FullData=$ClassName->get(); foreach ($FullData as $Data) { $Output.=''; } return $Output; }
谢谢
查看这篇文章:
function my_helper() { // Get a reference to the controller object //$CI = get_instance(); // use this below $CI = &get_instance(); // You may need to load the model if it hasn't been pre-loaded $CI->load->model('my_model'); // Call a function of the model $CI->my_model->do_something(); }
/sf/ask/17360801/