Welcome Guest, Not a member yet? Register   Sign In
Best Practice for view templates?
#3

[eluser]n0xie[/eluser]
There are many roads that lead to the same end result. We do it this way:

Code:
// default_template_view.php
<?php $this->load->view('template/_header_view.php'); ?>

      <div id="maincontent">
        &lt;?php echo $content; ?&gt;
    </div>

&lt;?php $this->load->view('template/_footer_view.php'); ?&gt;

// MY_Controller
        private $template = 'default_template_view';
        
        protected set_template($view) { $this->template = $view }
    protected function render($childdata = NULL)
    {
        if(! empty($childdata))
        {
            $data = array_merge($this->data,$childdata);
        }
        else
        {
            $data = $this->data;
        }
        $this->load->view($this->template, $data);
    }

// Some Controller that inherits from MY_Controller
    function index()
    {

        $data['content'] = $this->load->view('some_partial_view', $somedata,TRUE);
        $this->render($data);
    }

        function somefunction()
        {
                $data['content'] = $this->load->view('some_other_partial_view', $someotherdata, TRUE);
                $this->set_template('another_template');
                $this->render($data);
        }


Messages In This Thread
Best Practice for view templates? - by El Forum - 09-29-2009, 09:06 AM
Best Practice for view templates? - by El Forum - 09-29-2009, 09:32 AM
Best Practice for view templates? - by El Forum - 09-29-2009, 09:37 AM
Best Practice for view templates? - by El Forum - 09-30-2009, 02:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB