Welcome Guest, Not a member yet? Register   Sign In
Not wanting to use a template library, so is this an alternative that makes sense?
#1

[eluser]dallen33[/eluser]
I want to load almost all of my content into a single template I built (called user_page.php). Is this a good way of doing it?
Code:
$this->data['title']  = 'Sign In';
$this->data['content'] = $this->load->view('auth/login', $this->data, TRUE);
$this->load->view('common/user_page', $this->data);
#2

[eluser]skunkbad[/eluser]
I don't want to use template libraries either. I do as you have shown, instead of $this->data, I use $view_data.
#3

[eluser]jellysandwich[/eluser]
What's your reason for not wanting to use any template libraries?

If it's complexity/footprint, then I would recommend this:

http://maestric.com/doc/php/codeigniter_template

It's tiny - 1 variable and 2 functions, that's it.
#4

[eluser]aquary[/eluser]
What i did is to put my own template function into MY_Controller...
Code:
// Commoon template loader function
function _load_view($template=NULL, $view=NULL, $data=NULL){
   if(!empty($view))
      $data['view']=$view;
   $this->load->view($template, $data);
}

function _backend($view=NULL, $data=NULL){
   $this->_load_view('templates/backend', $view,  $data);
}

function _frontend($view=NULL, $data=NULL){
   $this->_load_view('templates/frontend', $view,  $data);
}

Then I could use either $this->_backend() or $this->_frontend() to load different template for different sections.

In your case you could totally made $data as optional, and pull data from $this->data directly before load the view.

Code:
function _load_view($template=NULL, $view=NULL, $data=NULL){
   if(!empty($view))
      $this->data['view']=$view;
   $this->load->view($template, $this->data);
}

function _frontend($view=NULL){
   $this->_load_view('templates/frontend', $view);
}

// then put this to load template
// $this->_frontend('yourview/view');

Actually it's quite nice to autometically pull data from $this->data.... I think I'll adapt your style to my code :3




Theme © iAndrew 2016 - Forum software by © MyBB