Welcome Guest, Not a member yet? Register   Sign In
header and footer functions
#1

[eluser]TheFuzzy0ne[/eluser]
Hi guys. I just need a little advice.

I would like to package my header, nav bar and footer functions out of the called controller. I'm not entirely sure whether they should have their own controllers, or whether it should all be put into libraries.

Am I right in saying that all controllers are available to be called upon publicly? I seem to remember reading that the controller can't be called upon publicly if it's prefixed with an underscore, but maybe I am confusing it with the controller methods.

The reason I'd like to keep them separate, is because the data in all three will be dynamically generated.

I'm actually quite confused as to what to do. I know I can include views from inside views, but I can't decide whether or not have the header/nav bar sent automatically or to manually send it each request. After all, there may be a time when I may not want to send the header, such as when sending a download.

I know that's a lot of thoughts there, but it's important to me that I get it right first time, as I always seem to settle on a solution, only to find I need to find a new one when it doesn't support a feature I had not considered before.

Many thanks.

Daz.
#2

[eluser]Pascal Kriete[/eluser]
Hey Daz,

There are a few solutions here. What you don't want is to have them in their own controller. Controllers take in and process page requests, you should try not to nest them. If you need common functions everywhere, you can either extend a common controller, or create a library/helper.

It depends very much on the application. For larger projects it can be beneficial to have a common controller to initialize your various libraries.

For small projects, I would just nest the views.

Cheers,
Pascal
#3

[eluser]gunter[/eluser]
there is this info in the user guide (controller)
Quote:Important: If your controller contains a function named _output(), it will always be called by the output class instead of echoing the finalized data directly. The first parameter of the function will contain the finalized output.

Code:
function _output($output)
{
    echo $this->load->view('header');
    echo $output;
    echo $this->load->view('footer');

}

the problem is, that the whole thing isnĀ“t cachable, only the $output will be cached - at least it was so in the last year when I tried it
#4

[eluser]TheFuzzy0ne[/eluser]
[quote author="inparo" date="1209325014"]Hey Daz,

There are a few solutions here. What you don't want is to have them in their own controller. Controllers take in and process page requests, you should try not to nest them. If you need common functions everywhere, you can either extend a common controller, or create a library/helper.

It depends very much on the application. For larger projects it can be beneficial to have a common controller to initialize your various libraries.

For small projects, I would just nest the views.

Cheers,
Pascal[/quote]

Nice one. Thanks! I keep taking for granted the fact I can extend classes. This whole OOP thing is awesome. I used to work with Dragonfly CMS (based on PHP-Nuke). There are a few objects there, but nothing seems quite so organised. Also the documentation is about as sparse as the hair on my head!
#5

[eluser]adwin[/eluser]
try FreakAuth pluggins for CI .. it has header and footer embeded in their templates.




Theme © iAndrew 2016 - Forum software by © MyBB