CodeIgniter Forums

Full Version: Autoloading HTML? Autoloading functions?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]dannydefcon[/eluser]
Is it possible to auto load the same html code for every View? For example I would create the design of the site in a php file called "header.php" that I want to be included in every View. Is this possible or do I have to include this file in every respective Controller?

Also, I know it's possible to autoload a model, but is it possible to have a particular function be run upon every page load?

El Forum

[eluser]mddd[/eluser]
Some people like to put some code in a hook or change the output class.
Personally, I just put a line " $this->load->view('header'); " in my view. That's easy because you can load a view from another view.
This way, you can easily select another header view for different kinds of pages, like an admin page.

As for models, there is always the class constructor which you can use to do stuff on loading.

El Forum

[eluser]2think[/eluser]
You may want to have a look at creating a controller or controllers that you then extend. What you essentially do is extend the Codeigniter controller class and put your html calls in there, maybe things like:

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

Then you can change $data as needed. I'm not sure if this answers your question but here is the Codeigniter Userguide page http://ellislab.com/codeigniter/user-gui...asses.html

El Forum

[eluser]jedd[/eluser]
[quote author="dannydefcon" date="1279186456"]Is it possible to auto load the same html code for every View?[/quote]

In the [url="/wiki/FAQ"]FAQ[/url] there's a question & answer that might be relevant - I keep repeating lumps of code - things like login-dialogs, stylesheets, headers, footers, or menus - is there some place I can define them just once?


This thread - [url="http://ellislab.com/forums/viewthread/110969/"]http://ellislab.com/forums/viewthread/110969/[/url] - might also be useful to read through.