[eluser]ytsejam[/eluser]
Hello,
I am a newbie in codeigniter. I want to learn using MY_Controller.php. Is it an advantage using to normal pages controller.
I used it in application/core/MY_Controller.php.
Code:
class MY_Controller extends CI_Controller {
protected $data = array();
function __construct() {
parent::__construct();
}
function render_page($view) {
//do this to don't repeat in all controllers...
$this->load->view('templates/header', $this->data);
//menu_data must contain the structure of the menu...
//you can populate it from database or helper
$this->load->view($view, $this->data);
$this->load->view('templates/footer', $this->data);
}
}
Code:
class Home extends MY_Controller {
public function view($page = 'home')
{
$this->load->helper('text');
$this->data['records']= $this->services_model->getAll();
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->render_page('pages/'.$page)
}
my config/routes.rb:
Code:
$config['index_page'] = 'index.php';
$config['subclass_prefix'] = 'MY_';
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
my views is in /application/views/pages/home.php.
I can only get the home.php in the source code. Can you show me my mistake?