Welcome Guest, Not a member yet? Register   Sign In
Website Layout
#1

[eluser]garycocs[/eluser]
Hi Lads,

Just wondering what peoples normal layouts for codeigniter are? I've been reading up a bit on it and there's a few different ways??

for a basic enough site like ratemypub.ie should I have

1 controller, and different functions for each webpage/view in that controller or seperate controllers for each webpage/view

Also people have their templates laid out differently?

Some peoples versions have the views

header.php
contnent.php
footer.php

The content for each content.php view changing depending on the page.

Where others recommend the view

template.php

which calls header.php and footer.php from within and somehow calls different content from within the template depending on what web page the user is requesting??

Coould someone point me in the right direction with these issues?? I've read up about each of them but am still a bit confused.

Thanks for anything ye can give me.
Gary
#2

[eluser]xwero[/eluser]
the template solution makes you write less code but it's more likely to have variable bugs as CI catches all variables passed to the views in a one dimensional array. So to be safe you do something like
Code:
$data['header'] = array(
                           'var1'=>'val1',
                           'var2'=>'val2',
                              );
// for content.php
$data['var1'] = 'val1';
If you can track all the variables you need to add to the view files you can use the load->vars method.
#3

[eluser]n0xie[/eluser]
[quote author="garycocs" date="1239164338"]
Where others recommend the view

template.php

which calls header.php and footer.php from within and somehow calls different content from within the template depending on what web page the user is requesting??
[/quote]
The template doesn't call 'different content', it is served different content depending on which controller it is called from. So let's say you have a template like this:
Code:
/* template view */
$this->load->view('header');

echo $content;

$this->load->view('footer');

And you have 2 controllers:
Code:
/* controllers/home.php */
$data['content'] = 'This is my home page';
$this->load->view('template', $data);

/* controllers/about.php */
$data['content'] = 'This is my about page';
$this->load->view('template', $data);

Now you have 1 'master' template which shows different content depending on which page the user is on.
#4

[eluser]garycocs[/eluser]
Hi,

Thanks for that lads.

Does that mean you have to pass an entire pages content i.e. sidebar main content etc in one variable $data['content'] seems like a lot of information to me?? But maybe I just have to change my thinking.

Thanks again,
Gary
#5

[eluser]xwero[/eluser]
If you feel uncomfortable passing the whole partial to the template you can make it as follows
Code:
$this->load->view('header');
$this->load->view($content);
$this->load->view('footer');
Then you have a reserved variable $content. And because it's php only you can add the defaults there too instead of in a config file
Code:
$header = ( ! isset($header))? 'header':$header;
$content = ( ! isset($content))? 'content':$content;
$footer = ( ! isset($footer))? 'footer':$footer;

$this->load->view($header);
$this->load->view($content);
$this->load->view($footer);




Theme © iAndrew 2016 - Forum software by © MyBB