![]() |
TUTORIAL : templates using nothing but CI code - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: TUTORIAL : templates using nothing but CI code (/showthread.php?tid=14243) |
TUTORIAL : templates using nothing but CI code - El Forum - 12-24-2008 [eluser]xwero[/eluser] I see a lot of people are struggling to remove common page parts from the controller methods. Rather than writing use this or that library i decided to share a way to do this without third party code. What do we need: - one developer - hooks enabled - know that the load->vars method exists The two hooks we are going to use are the post_controller_constructor and post_controller. The post_controller_constructor loads common variables and if you don't use a template you can load your header. The post_controller loads the template or the footer. Let's see some code in case you want to load header and footer. application/hooks/page_parts.php Code: function header() Code: $hook['post_controller_constructor'] = array( For a template it's almost the same but then there is no need to have a header function. application/views/pageparts/template.php Code: <html> Code: function post_constructor() Code: $hook['post_controller_constructor'] = array( Code: class Random_controller extends Controller And this concludes the tutorial. Enjoy the end year festivities! TUTORIAL : templates using nothing but CI code - El Forum - 12-24-2008 [eluser]manilodisan[/eluser] We use something else but similar to avoid repetitive code such as headers, footers, menus etc. I like smart, good practices. Thanks for sharing @xwero. |