Pages

Search This Blog

Calling Codeigniter Controller Methods from Inside View

When I tried to make my own MVC Framework with PHP, I found the way how to Calling Codeigniter Controller Methods from Inside View. Maybe I am ver lucky, because I didn't find the way from internet, I just write the code once, and, viola... I got it. :D. But I dont't sure that is the best way for use Codeigniter Controller Methods from Inside View. Oke, for example, I have Controller file like this:

class Example extends CI_Controller {
 function __construct()
 {
  parent::__construct();
 }
 function show(){
  echo "show";
 }
}

The first step is you have to reassign the Codeigniter object to a variable on the your view files.

$this->method_call =& get_instance();

And then, you can call the controller methods from inside view.

$this->method_call =& get_instance(); 
$this->method_call->show();

Simple, right? :D

No comments:

 

Most Reading