Welcome Guest, Not a member yet? Register   Sign In
reset data values in repeatedly used nested view
#1

[eluser]pocketmax[/eluser]
Check this out...

Code:
<body>

$this->load->view('tile',array('foo'=>'bar'));
$this->load->view('tile');

</body>

When I run my code. The values I put into the first tile view are also in the second. Is there a way to have CI reset the values in a repeatedly used view? I could easily just use unset inside the tile view but I would think there would be a more elegant way of doing it within ci.
#2

[eluser]InsiteFX[/eluser]
Why are you loading the view twice?

Load your view in the controllers index function.
Code:
function index()
{
    $data = array();

    $data['foo'] = 'bar';

    $this->load->vars($data);
    $this->load->view(title);
}

Now in your view just do this:
Code:
<?php echo $foo; ?>

InsiteFX
#3

[eluser]pocketmax[/eluser]
The reason why I'm loading the view twice is because I want to repeat the view a few times on the page but some times with different combos of data and other times with no data. So something like...

Code:
<body>

//I load foo and test into the view
$this->load->view('tile',array('foo'=>'bar','test'=>'testing123'));
//I load the view again with test but not foo so I shouldn't see foo's value
$this->load->view('tile',array('test'=>'testing123'));
//I just want to load the tile with no values
$this->load->view('tile');

</body>
#4

[eluser]Cristian Gilè[/eluser]
In your controller create an array like this:

Code:
$data['first_combo']  = array('foo'=>'bar','test'=>'testing123');
$data['second_combo'] = array('foo'=>'bar');
$data['third_combo']  = array();

and pass this data to the view

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


In the view you can process each array and check if are empty. If not populate your combos.




Theme © iAndrew 2016 - Forum software by © MyBB