CodeIgniter Forums
[SOLVE]how pass data to subviews - 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: [SOLVE]how pass data to subviews (/showthread.php?tid=24074)



[SOLVE]how pass data to subviews - El Forum - 10-29-2009

[eluser]li9ht[/eluser]
mycontroller.php
Code:
$data = array("content" => "blabla bla");
$this->load->view("template.php",$data);

template.php
Code:
<?php
$this->load->view('header.php');
?>
<div id="content">
&lt;?=$content;?&gt;
</div>

header.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php=$title;?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;



question.. how do i load data into $title?
any other simpler way or am i doing it wrongly..?


[SOLVE]how pass data to subviews - El Forum - 10-29-2009

[eluser]CroNiX[/eluser]
in your controller:
Code:
$data['title'] = 'this is the title';
$data['content'] = 'here is some content';
$this->load->view('header', $data);
$this->load->view('template', $data);

Id remove loading the header from within the content template.


[SOLVE]how pass data to subviews - El Forum - 10-29-2009

[eluser]Thorpe Obazee[/eluser]
Code:
$data['title'] = 'this is the title';
$data['content'] = 'here is some content';
$this->load->vars($data);
$this->load->view('header');
$this->load->view('template');



[SOLVE]how pass data to subviews - El Forum - 10-30-2009

[eluser]puzzlebox[/eluser]
or this:

$data= array('title'=>'this is the title',
'content'=>'here is some content');
...
..
.


[SOLVE]how pass data to subviews - El Forum - 10-30-2009

[eluser]li9ht[/eluser]
Quote:Id remove loading the header from within the content template.
any specific reason why..?


solve it by declaring the global var using
Code:
$this->load->vars()
and still using the same master template