CodeIgniter Forums
How is good way to use hooks - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How is good way to use hooks (/thread-29914.html)



How is good way to use hooks - El Forum - 04-26-2010

[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?


How is good way to use hooks - El Forum - 04-26-2010

[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');


How is good way to use hooks - El Forum - 04-26-2010

[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");
?>


How is good way to use hooks - El Forum - 04-26-2010

[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.


How is good way to use hooks - El Forum - 04-26-2010

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


How is good way to use hooks - El Forum - 04-26-2010

[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


How is good way to use hooks - El Forum - 04-26-2010

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


How is good way to use hooks - El Forum - 04-27-2010

[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.