Welcome Guest, Not a member yet? Register   Sign In
cleanest way to implement the main layout
#6

[eluser]wiredesignz[/eluser]
Always use a parent controller and NEVER repeat code if you don't have to.
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{    
    function __construct()
    {
        parent::__construct();
        
        $this->load->helper(array('url','form'));
    }    
    
    function _remap($method)
    {
        $data =& $this->load->_ci_cached_vars;

        $data = $this->config->item('settings');
        
        $data['page']    = strtolower(get_class($this));
        $data['method'] = $method;
        
        if (method_exists($this, $method))
        {
            $data['content'] = call_user_func_array(array($this, $method), array_slice($this->uri->segments, 2));
        }
        else
        {
            show_404();
        }
                    
        $this->load->view('layout', $data);
    }
}
EDIT: Added load->vars() to allow page controller view to access config settings


Messages In This Thread
cleanest way to implement the main layout - by El Forum - 04-06-2011, 02:50 PM
cleanest way to implement the main layout - by El Forum - 04-06-2011, 03:47 PM
cleanest way to implement the main layout - by El Forum - 04-06-2011, 05:29 PM
cleanest way to implement the main layout - by El Forum - 04-14-2011, 03:51 PM
cleanest way to implement the main layout - by El Forum - 04-14-2011, 10:35 PM
cleanest way to implement the main layout - by El Forum - 04-14-2011, 11:48 PM
cleanest way to implement the main layout - by El Forum - 04-15-2011, 09:20 AM
cleanest way to implement the main layout - by El Forum - 04-15-2011, 01:15 PM
cleanest way to implement the main layout - by El Forum - 04-15-2011, 05:14 PM
cleanest way to implement the main layout - by El Forum - 04-15-2011, 05:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB