[eluser]Perkin5[/eluser]
I am using a template and passing views into the template via a data array in the usual way like this:
Code: $data = array(
'body_id' => 'some_id',
'title' => 'some_title',
'nav' => $this->load->view('nav_view','',true),
'main' => $this->load->view('some_view','',true),
'foot' => $this->load->view('footer_view','',true)
);
$this->load->view('template_view', $data);
but now supposing I want to load some data (say a variable $extradata) into some_view - I tried this:
Code: 'main' => $this->load->view('some_view',$extradata,true)
but it doesn't work.
I tried adding a term to the data array like this:
Code: 'extra' => $extradata
but although the variable $extra is available in the main template, it doesn't appear to be available in a sub-view.
Grateful for advice on how I can pass data specifically to one of the sub-views, itself loaded as data.
[eluser]xjohnson[/eluser]
Hi, Perkin5 -
Can you provide an example of how you're setting the value of $extradata?
For example:
Code: $extradata = array(
'foo' => $this->load->view('bar', '', TRUE)
);
xjohnson
[eluser]Perkin5[/eluser]
Thanks for responding.
Like this:
Code: $extradata = array(
array('Meeting','Date','Location','Details'),
array('Spring ','Wednesday 26 March 2012','Main Hall','Coffee 10.30 am Finish approx 3.15 pm'),
array('Summer','Wednesday 22 June 2012','Main Hall','Coffee 10.30 am Finish approx 3.15 pm'),
array('Autumn','Tuesday 27 October 2012','Assembly Room',''),
array('Winter','Wednesday 9 December 2012','Assembly Room','')
);
- and having passed the variable $extradata, in the view I want to do:
Code: echo $this->table->generate($extradata);
[eluser]OliverHR[/eluser]
In the controller
Code: $more_data['extradata'] = array(
array('Meeting','Date','Location','Details'),
array('Spring ','Wednesday 26 March 2012','Main Hall','Coffee 10.30 am Finish approx 3.15 pm'),
array('Summer','Wednesday 22 June 2012','Main Hall','Coffee 10.30 am Finish approx 3.15 pm'),
array('Autumn','Tuesday 27 October 2012','Assembly Room',''),
array('Winter','Wednesday 9 December 2012','Assembly Room','')
);
$data = array(
'body_id' => 'some_id',
'title' => 'some_title',
'nav' => $this->load->view('nav_view','', TRUE),
'main' => $this->load->view('some_view', $more_data, TRUE),
'foot' => $this->load->view('footer_view','', TRUE)
);
$this->load->view('template_view', $data);
In some_view:
Code: echo $this->table->generate($extradata);
[eluser]Perkin5[/eluser]
God bless you man! It works and I can even see the logic of it. I'll go to bed happy tonight.
|