Welcome Guest, Not a member yet? Register   Sign In
GLOBAL variable
#18

[eluser]Mike Chojnacki[/eluser]
[quote author="jtrainaldi" date="1310523796"]How would you deal with a variable that you plan on using multiple times within your site. For example I have an array of states ($state_list) that will populate a drop down form with all of the states of the US.

Rather than copying and pasting the array on each form what is the preferred method of assigning that variable "globally" and re-using it throughout the site.

Thanks in advance.[/quote]

Create a helper and give it a function like:

print_state_list()
{
// your array
$state_list = array();
// return the array
return $state_list();
}

Then add the helper to autoload in the autoload file in the config folder and you can just call <?=print_state_list()?> in any view to access the state list.


Messages In This Thread
GLOBAL variable - by El Forum - 08-28-2008, 02:18 PM
GLOBAL variable - by El Forum - 08-28-2008, 02:28 PM
GLOBAL variable - by El Forum - 08-28-2008, 02:40 PM
GLOBAL variable - by El Forum - 08-28-2008, 02:42 PM
GLOBAL variable - by El Forum - 08-28-2008, 02:43 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:17 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:22 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:27 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:32 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:37 PM
GLOBAL variable - by El Forum - 08-28-2008, 03:48 PM
GLOBAL variable - by El Forum - 09-01-2008, 12:50 PM
GLOBAL variable - by El Forum - 09-01-2008, 03:37 PM
GLOBAL variable - by El Forum - 09-02-2008, 03:13 AM
GLOBAL variable - by El Forum - 09-02-2008, 01:13 PM
GLOBAL variable - by El Forum - 05-19-2010, 04:33 AM
GLOBAL variable - by El Forum - 07-12-2011, 03:23 PM
GLOBAL variable - by El Forum - 07-13-2011, 08:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB