Welcome Guest, Not a member yet? Register   Sign In
variables in the view
#1

[eluser]Unknown[/eluser]
Say for instance you are loading a few variables like this in the controller and sending to the view:

Code:
$this->load->vars($data);
$this->load->view('thanks');

How would I access the individual variables in the data array in the view without knowing the actual names of the variables (title or whatever)

To give you a small bit of background. I want to process lots of different forms with the one function so the individual elements of the data array are not always the same...

Thanks
#2

[eluser]wiredesignz[/eluser]
Your view variables are stored by CodeIgniter in the loader object variable $_ci_cached_vars...
Code:
print_r($this->load->_ci_cached_vars);
#3

[eluser]NogDog[/eluser]
You can pass an associative array as the 2nd arg to the load->view(), and in the view each array index will be available as a variable of the same name with its value the corresponding value in the array for that key.
#4

[eluser]daveWid[/eluser]
NogDog has you in the right direction. So you can change your code to...

Code:
$this->load->view('thanks', $data);

And in your thanks view use the array key as the data.

Code:
<?php echo $ARRAY_KEY; ?>

changing ARRAY_KEY to the data you want to access. (or however you want to use it)
#5

[eluser]Fero[/eluser]
The meant something like

$data['name_of_variable']="Oh Yeah";
$data['name_of_another_variable']="Oh YeaH I really want it";

and then you pass it as $this->load->view('thanks',$data);

Then, in View you can access $name_of_variable containing Oh Yeah and similar for name_of_another_variable Smile




Theme © iAndrew 2016 - Forum software by © MyBB