CodeIgniter Forums
Passing data to a view within a view: Why doesn't this work? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Passing data to a view within a view: Why doesn't this work? (/showthread.php?tid=32339)



Passing data to a view within a view: Why doesn't this work? - El Forum - 07-20-2010

[eluser]dallen33[/eluser]
Code:
$title = 'Home';
$data['header'] = $this->load->view('header', $title, TRUE);
$data['footer'] = $this->load->view('footer', '', TRUE);
$this->load->view('home', $data);

In the view header.php, I have <?php echo $title; ?>

Any idea why this doesn't work? The error is that title is an undefined variable.


Passing data to a view within a view: Why doesn't this work? - El Forum - 07-20-2010

[eluser]dallen33[/eluser]
Controller
Code:
$data['title']    = 'Home';
$data['footer'] = $this->load->view('footer', '', TRUE);
$data['data']    = $data;
$this->load->view('home', $data);

View
Code:
<?php echo $this->load->view('header', $data); ?>

This works!

<?php echo $footer; ?>

This works, but seems clumsy.


Passing data to a view within a view: Why doesn't this work? - El Forum - 07-20-2010

[eluser]WanWizard[/eluser]
Shouldn't the second parameter be an array?
Code:
$data['title'] = 'Home';
$data['header'] = $this->load->view('header', $data, TRUE);



Passing data to a view within a view: Why doesn't this work? - El Forum - 07-20-2010

[eluser]dallen33[/eluser]
Works, thanks!