Welcome Guest, Not a member yet? Register   Sign In
Simple Question Regarding Variables
#1

[eluser]Jesse Schutt[/eluser]
Morning all from Frozen Northern Wisconsin!

I have a simple question for you. In my controller I would like to have several variables available through all my functions. How should I go about this?

Example - I would like to define $admin_email in one place and be able to reference it in several of my functions.

Thanks!

Jesse
#2

[eluser]xwero[/eluser]
use a config file and autoload it.
#3

[eluser]Jesse Schutt[/eluser]
Thanks xwero.

I am wanting to define a public variable for just that specific controller. Is it better to use
Code:
public $admin_email = '[email protected]';
and reference it through $this->admin_email, or to use the config as you suggested?

Thanks!
#4

[eluser]xwero[/eluser]
Sorry you were talking about class variables. It depends on whether the variable should be accessible from outside the class (public) or it can be altered by the dependent classes (protected) or only by the class it is in (private).
#5

[eluser]Jesse Schutt[/eluser]
Xwero - Sorry for my lack of clarity :-)

It's hard to write out what I am looking for because I don't know the terms! What I would like to accomplish is have items like the admin_email, event_id, and event_title available to all of the functions in my Action.php controller. I would like to define them once and be able to reference them throughout that one controller. The functions don't need to modify the values.

Does that make sense? I'm sure this is pretty basic stuff, I just don't know where to look!

Jesse
#6

[eluser]GSV Sleeper Service[/eluser]
Hi Jesse,

if you just want these vars available throughout just one controller then using
Code:
private $admin_email = '[email protected]';
is the way to go, you'd then access this throughout your controller/class using
Code:
$this->admin_email;
if they're not going to change, you could use class constants, eg
Code:
const ADMIN_EMAIL = '[email protected]';
these can be accessed in your class using
Code:
self::ADMIN_EMAIL;
#7

[eluser]Jesse Schutt[/eluser]
Thanks!

This is going to sound like a stupid question, so bear with me!

If "private" will create the variable for just one controller, what is the scope of "public"?
#8

[eluser]GSV Sleeper Service[/eluser]
public means it's available everywhere, see this page for more details.
http://uk3.php.net/manual/en/language.oo...bility.php




Theme © iAndrew 2016 - Forum software by © MyBB