CodeIgniter Forums

Full Version: Separated head, column, body and footer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

As a newbie I still need to independently create each part of my web, by using a header.php for the header, a footer.php which will display footer notes and so.
When I try to make use of controllers and views, I just can render one view, so I don't know how should I make to generate a header or a menu with contextual content.

The only thing I got is a view file which includes a header view file and a footer view file, but I must generate all code from my controller to render the controller itself, the header and the footer, and I'm going crazy.

Is there any common way of creating separated "pieces" of the web with a MVC layout? How are you making this?

Please, help!

El Forum

btw, yes, I've checked "Header and Footer and Menu on every page" wiki page, but those approaches point to a layout resolution, but not about the data generation.
Let me explain it:

1. I have a header :-)
2. My header show common information for ALL pages on my site, like:
- application name, from my config file
- user greeting, from session info
- date and time from live system
3. I have a controller that gets a list of products and triggers products_view
4. I have a products_view view which shows the list of products got from the controller

In this moment I need to generate header data and products data from the same controller method I'm calling the view.
When I have 10 controllers, will I need to generate header data from each of them so I can display a view?

How do you manage this? aarghh!! I can't see it! My mind is not ignited!

El Forum

[eluser]Rob Gordijn[/eluser]
Hey Wazzu,

you can use:

in the controller.
or just:

and load the header and footer in that page-view.

or, use a container-view:


and in the controller:
$this->data['page'] = 'my_page';
$this->load->view('container', $this->data);


El Forum

Thanks for your answer, Rob, but that's not the problem. I'm already using that method to include several views within one view, but see:
In your controller you have:
$this->data[‘page’] = ‘my_page’;
$this->load->view(‘container’, $this->data);
But you would need to have generated all data from head and foot views, too. When you parse head or foot view, you need to pre-generate all $data variables for them, so your controller would have to:
- generate header data
- generate self data
- generate footer data
- load container view

That means that you'll have to generate header and footer data in every controller you make, ant that's a problem (for me at least)

Do you get my question? Any other idea?

El Forum

this has been asked over and over again.
Take a look here:

El Forum

[eluser]Rob Gordijn[/eluser]
ow, I see your problem.

My solution is to create an MY_Controller libary.

class MY_Controller extends Controller
    public function __construct()
        // default header/footer data generation here

and extend your controller with MY_Controller instead of Controller.

Makes me feel more in control.


p.s. I see that I didn't code php 4 compat. sorry for that Tongue

El Forum

Hmmm, now I understand why so many people creates that "parent" controller. Things are making sense now :-)

[quote author="Rob Gordijn" date="1264777834"]p.s. I see that I didn't code php 4 compat. sorry for that Tongue[/quote] php4 is for dinos! hahahaha

Thanks for your explanation