I want to load data to my view, particularly a variable in my controller items
.
But in my controller I want to dynamically set what items
is before it is push to the view.
I tried the code below but it doesn't work. The view loads up with an error "Undefined variable: items" .
public function index(){
if ($this->input->post('filter'))
{
$search = $this->input->post('filter');
$test=$this->upload_model->test_r();
$data['items']=$test;
}
else
{
$data['items']=$one;
}
$data=array ('other'=>$othrs, 'links'=>$links);
$this->load->view('gallery_view', $data);
}
How I would like this to work is that $data['items']
is set to $one
by default, when the page loads up, but on the page I have a select box, so I want that if the select box is is changed that $data['items']
would be set to something else. But this is only if the select box is used, else, it should look up with the $data[items]=$one
. The $data array has other values that need to be loaded in the view such as "others" and "links".
The select box on my view
<?php echo form_open(base_url().'page') ?>
<form class="form-inline" role="form">
<select class="form-control" id="filter" name="filter" onchange="this.form.submit()">
<option value="1">1</option>
<option>2</option>
<option>3</option>
</select>
</form>
<?php echo form_close(); ?>
The index controller function above is for my controller "Pages". The value from the select box is captured fine, when I do an echo on the value passed it shows up correctly.
The problem is getting the view data "items" to change depending on if the select box is used.
How do I fix this?