CodeIgniter Forums

Full Version: How is good way to use hooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]WebMada[/eluser]
Hi!

General pattern of today's webpages are header-main content-footer, header & footer are often static
I see when searching that we often use hooks when creating $GLOBALS variables to use in header and footer
Is is the best way?

El Forum

[eluser]Unknown[/eluser]
I tend to just have my header and footer in two separate views, passing variables to them for meta data, title, css files etc.

An example could be:

$data = array(
'title' => 'Title',
'meta_keywords' => 'Keywords, go, here',
'meta_desc' => 'Description is here',
'css' => 'css.css',
'js' => 'js.js'
);

$this->load->view('page_head', $data);
$this->load->view('index');
$this->load->view('page_foot');

El Forum

[eluser]WebMada[/eluser]
I admit that this is another way but it's too heavy: always calling header and footer in each call of a page
Generally, don't we use:
<?php
$this->load->view("vwHeader");
?>
..........
<?php
$this->load->view("vwFooter");
?>

El Forum

[eluser]Zeeshan Rasool[/eluser]
[quote author="WebMada" date="1272309209"]I admit that this is another way but it's too heavy: always calling header and footer in each call of a page
Generally, don't we use:
<?php
$this->load->view("vwHeader");
?>
..........
<?php
$this->load->view("vwFooter");
?>[/quote]
Agreed ! actually its simple way to do that. If the header and footer are not static and vary from page to page then we can call them in controller as partial or using parser.

El Forum

[eluser]WebMada[/eluser]
Let's go to my first question, what about hooks? When to use it

El Forum

[eluser]paulc010[/eluser]
Hooks aren't that useful for this I don't think. Maybe for post-processing, but not much else really. Have you looked at any of the template libraries, combined with some form of "Modules"?

Paul

El Forum

[eluser]WebMada[/eluser]
I thought that we use hooks when header & footer contains datas like dynamic menus, etc.

El Forum

[eluser]mddd[/eluser]
Hooks are for doing things before or after the regular processing of CI.
Maybe your php server needs some special settings. Or you want to load a database in a special way. That kind of things.
Loading data, outputting views etc. should be done in the normal way - through your conroller, models and views.