TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-28-2009, 01:38 PM   #1 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default 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:
function index()
{
$this->load->view('header');
$this->load->view('index');
$this->load->view('footer');

The thing is, within the header file is the HTML code that shows the menu's and stuff, which is the same on each page. Some menu items need stuff working out first, so I did this:

PHP Code:
function index()
{
$next_fixture get_next_fixture()

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

private function 
get_next_fixture()
{
$fixtures $this->db->get('fixtures');

// Do rest of processing in this function....
// ...
// ...
return $whatever_array;

This works a treat, and in my header file I can just echo
PHP Code:
$date_of_fixture
etc wherever I need it in my menu bar.

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:
echo $some_variable_that_the_function_created
?

Thanks

I know it's a bit long winded but I've tried to give plenty of info so you guys can help.
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM


All times are GMT. The time now is 06:04 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design