Welcome Guest, Not a member yet? Register   Sign In
Global variables, set defined variables
#1

[eluser]bigdaddysheikh[/eluser]
Hey guys,

I have been searching for this topic for quiete sometime and have not found what I am looking for. So here it goes.

I keep having undefined errors from CI. Although it is not PHP errors, I know it is bad practice. First, is there a way to define these variables in the controller so it can be sent through different functions.

Currently, I am trying to use a variable that will hold URLS that I want to display in many sub functions of the mother controller. Rather than me declaring this variable in every function, how can I set this variable only once.

Last but not least, is there a better way to pass arrays to views.
example
Code:
$data["foo"][0] = "test";
$data["foo"][1] = "test1";

I did try this, but it does not work:
Code:
$data["foo"] = "test";
$data["foo"] = "test1";
#2

[eluser]Colin Williams[/eluser]
Code:
$data["foo"][] = "test";
$data["foo"][] = "test1";

That ought to work. It will be $foo[0] and $foo[1] in your view.

If I'm going to be sharing variable throughout different areas of an application, I'll usually just create a config file for it and load it with the Config class.




Theme © iAndrew 2016 - Forum software by © MyBB