有没有办法从我们的视图中使用codeigniter调用控制器内的方法。我知道这是一个不好的做法但是,现在我强迫这样做。谢谢你
If you want to call a function of the current controller, you have to get the instance of the current controller this way:
<?php
$CI =& get_instance();
$CI->your_method($param);
?>
You can just do:
$this->controller_method();
While this might answer your question, I personally agree with the comments of – Matthew J Morrison and DamienL.
In controller:
$this->method_call =& get_instance();
In view
$this->method_call->show();
in your controller put
$data['myClass'] = $this;
That way when you send the data to the view, it will load the controller :)
Then you can access the methods like
$myClass->method();
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.