Welcome Guest, Not a member yet? Register   Sign In
Which template method is better practice
#1

I'm looking for a "good practique" for templating in codeigniter (actual version) (sorry for my bad english). All info I have founded is really old and has many options to do the same, but I can't understad which one of those methods are better of if there is a standar way for doing that. I'm gonna describe the best tree methods I have found in mi opinion and the idea is to know which one is a better choice (cleanest, simplest, and codeigniter patron oriented).

Method 1: extendidng controller class: I think that this method is easy to implement and very usefull, but it means to change all controllers logic


PHP Code:
class MY_Controller extends CI_Controller{

 public function 
__construct(){
      parent::__construct();
 }

 public function 
loadPage($contentView false$data = array()){
      if(!$contentView$contentView 'home';
      $this->load->view('header'$data);
      $this->load->view($contentView$data);
      $this->load->view('footer'$data);
 }



and for the controllers do something like:

PHP Code:
class Pages extends MY_Controller {




Method 2: doing the same but with a loader (I'm not sure about how to do this)

Method 3: doing the same with a library (I'm not sure about how to do this)

Method 4: Doing a template view that loads the partials

Other methods that I don't know...

The idea is to have many templates, for example with top nav bar, another one with lef side menu and load the template in the contreoller passing expecifically the view who need to insert in the template (and it's data array).

Are one of these methods recommended? or any better way for doing this?
Reply
#2

Hello carlosvo !
To load partials, I usually use helpers: https://codeigniter4.github.io/userguide...ht=helpers
Wouldn't it work for you ?
Reply
#3

(02-07-2020, 10:40 AM)littlej Wrote: Hello carlosvo !
To load partials, I usually use helpers: https://codeigniter4.github.io/userguide...ht=helpers
Wouldn't it work for you ?
hi, thanks for the reply. It seems to be the way to do in codeigniter 4. Could be the best way in codeigniter 3 too? I have many methods that works for doing that, the problem is that I don't know which one is better or if anyone is a bad practice.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB