Skip to content

Instantly share code, notes, and snippets.

@yuya-matsushima
Created March 29, 2011 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuya-matsushima/892496 to your computer and use it in GitHub Desktop.
Save yuya-matsushima/892496 to your computer and use it in GitHub Desktop.
MY_Controller.php
<?php
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
// The easy way to use model in controller
// http://elliotscode.com/2011/03/28/codeigniter-my-controller/
protected function model($name)
{
$name = $name . '_model';
if( ! isset($this->{$name}))
{
$this->load->model($name);
}
return $this->{$name};
}
//The easy way to call view in controller
protected function view($name, $data = array(), $return = FALSE)
{
$name = $name . '_view';
return $this->load->view($name, $data, $return);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment