![]() |
CodeIgniter - globally used function
Hi all, I've recently started using CodeIgniter to code my next project, but it's the first time I've used a framework of any sort. My site follows a template using a generic header and footer, so loading a particular page might look like this:
PHP Code:
PHP Code:
PHP Code:
Ok, now we get on to my problem :-( This function would need to be called and then passed to the header in each of the files I created. Because the function is to be shown on every page how would I go about making this function be called and displayed in the header view automatically? I realise I would have to create a seperate file with the function in it, but would this file be a helper? A class?? :-/ And then, once I've created this so anything can access it, how would I go about calling it for every page so that the header view can just PHP Code:
Thanks :-) I know it's a bit long winded but I've tried to give plenty of info so you guys can help. |
You can create a helper in the application/helper/ folder e.g. /application/helper/myfunction_helper.php (include _helper or it wont work), then you can either load the helper in each file using $this->load->helper('myfunction'); as you already know. But you can also autoload it by adding it to the helper autoload array in application/config/autoload.php
CodeIgniter has a nice template parser, but it aint perfect imo :) |
Quote:
PHP Code:
|
why not calling your function in the header, rather than calling it in the controller?
my advice doesn't follow CI's default model but there shouldn't be any problems.:-D --- Web Design - Web Development - Web Consulting |
| All times are GMT. The time now is 08:20 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0