如何将参数传递给包含的视图模板?
控制器
public function action_index3()
{
$view = View::factory('view1');
$view ->set('name','Tokyo');
$view ->set('age','1980');
$this->response->body($view);
}
view1.php
<?php
include 'view2.php';
?>
<?php echo $name; ?><?php echo $age; ?>
如何将变量传递给模板view2.php?只有GET包括'view2.php?name ='+ val?
答案 0 :(得分:4)
public function action_index3()
{
$view = View::factory('view1');
$view ->set('name','Tokyo');
$view ->set('age','1980');
$subview = View::factory('view2');
$subview->set('meow', 'woof');
$view ->set('subview', $subview);
$this->response->body($view);
}
然后在你的视图中回显$ subview。
答案 1 :(得分:1)
您也可以使用View::set_global($key, $value)