Calling controller methods from inside view in Codeigniter
Is there a way to call a method inside the controller from our view开发者_StackOverflow社区 using codeigniter.I know it is a bad practice but, now I force to do this.Thank you
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();
精彩评论