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

[eluser]Josh Bright[/eluser]
One solution is to create a library, something along these lines:
Code:
class Template {
     public $ci;
     public $default_view;

     public function __construct() {
          $this->ci &= get_instance();
          $this->default_view = "template/render_view";
     }

     public function render($data, $different_view = NULL) {
          if (is_null($different_view)) {
               $this->ci->load->view($this->default_view, $data);
          } else {
               $this->ci->load->view($different_view, $data);
          }
     }
}

Then, in your controller:
Code:
public function index() {
          $data['content'] = "Some data goes here";
          $this->template->render($data);
     }


I haven't used this yet, beyond a little test that I just created, but, it appears to work fine. Up until now i've been just passing all my data to a 'template view', which loads in the 'skeleton' html that goes around the actual content im trying to display. To do this, i'll have a few variables I load in my MY_Controller, things like html_header_view, page_header_view, navigation_view, etc. These things could pretty easily be added to this template class so that everything is in one nice spot. In any case, your no longer having to type in your main view you load on every page request, along with the ability to send in a different 'main_view' if you wanted to.


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