Welcome Guest, Not a member yet? Register   Sign In
Extending the Controller to avoid code duplication
#11

[eluser]Barber of Padua[/eluser]
So, combining all suggestions the final code is like this:

Ditched the MY_Controller

Code:
class Page extends Controller {

    function Page()
    {
        parent::Controller();
        $this->getMainNav('globalmenu');
    }

    function index()
    {
        $data = array();
        
        $data['content'] = $this->Pages_model->getPageData('home');
        $this->load->vars($data);
        $this->load->view('main_layout');    
    }

    function contact()
    {
        $data = array();
        // etc        
    }

    function getMainNav($menu)
    {
        $data = array();

        $data['main_nav'] = $this->Pages_model->getNav($menu);
        $this->load->vars($data);
    }
}

simpler and cleaner :-)
Thanks for the great feedback, all of you!
#12

[eluser]Xeoncross[/eluser]
I thought that the point of this post was that you needed the "getMainNav" in other controllers - oops my mistake.




Theme © iAndrew 2016 - Forum software by © MyBB