Welcome Guest, Not a member yet? Register   Sign In
Passing variables to view with using variable names as indexes
#1

[eluser]MathBoon[/eluser]
Hi,

i was just wondering if there's a possibility to use the variable names for the indexes when passing an array to the view:

Code:
$data = array($something);

$this->load->view('someview',$data);

So that i can use the variable "something" in the view:
Code:
<div>&lt;?=$something;?&gt;</div>


My question is simply if i could write a little bit less code by not defining the index like i'm doing here:
Code:
$data = array('something' => $something);

Thanks in advance!
#2

[eluser]Aken[/eluser]
You would have to rig up some sort of function to parse the variable name from whatever variable scope you have (probably GLOBALS), and then add it to your array somehow. Either way, you're probably adding a lot more work rather than just writing the array keys like you normally would.

See this PHP.net comment for an idea of how you can parse the name.
#3

[eluser]MathBoon[/eluser]
Hmm ok, i thought there might be an easy way or even a build-in CI option.

Thanks for your reply, seems like i have to just write down the array keys Smile




Theme © iAndrew 2016 - Forum software by © MyBB