0

这适用于 Kohana 2.3.2

我最近开始让我的观点更有活力。使用默认模板视图作为基础,现在我在控制器中做

$this->template->innerView = new View('article');

然后,在我的中间template.php,我有

<?php echo $innerView; ?>

在我的页眉和页脚之间呼应文章视图的“胆量”。这很好用,除了我定义的所有变量$this->template都无法从新视图中访问。我知道我可能会做

$this->template->innerView->title = 'My Title';

但是如果有办法让子视图继承父视图的变量,那就太好了。

有没有?

4

2 回答 2

4

set_global() 方法仅将变量设置为在所有视图中都是全局的。当您在 PHP 中听到“全局”时,这不是您的想法,所以您做对了,这正是您想要使变量在多个视图中可用时应该使用的。

于 2009-05-11T10:55:02.533 回答
-1

http://docs.kohanaphp.com/core/view#set_global

我需要这个,因为我使用普通模板中的页面标题(for inside <title></title>)以及<h2></h2>页面的。

就这么简单

$this->template->innerView = new View('article');
$this->template->set_global('title', 'My Title');
于 2009-05-11T05:53:02.197 回答