![](/img/trans.png)
[英]Can I include a view in Kohana 3 that is not within `application/views`?
[英]Kohana - Views Within Views
我在通过视图传递变量时遇到问题。 但是,首先一些代码
// i enter the url http://localhost/my_projects/blog/index/index
// classes/controller/index.php
class Controller_Index extends Controller
{
protected $rendered_view;
public function before()
{
$this->rendered_view = View::factory('index')
->set('head', View::factory('subpages/head')
->set('title', 'Site title')
)
->set('nav', View::factory('subpages/nav')
->set('title', 'Site title')
)
->set('header', View::factory('subpages/header')
->set('h1', 'Header H1')
)
->set('sidebar', View::factory('subpages/sidebar')
->set('h1', 'Header H1')
)
->set('content', View::factory('subpages/content')
->set('h2', 'Header H2')
->set('content', 'some content')
)
->set('footer', View::factory('subpages/footer')
->set('footer', 'some footer')
);
}
public function action_index()
{
$this->response->body($this->rendered_view);
}
}
在视图索引中,我将变量传递给默认视图:
// views/index.php
echo View::factory('default')->set('head', $head);
echo View::factory('default')->set('nav', $nav);
echo View::factory('default')->set('header', $header);
echo View::factory('default')->set('sidebar', $sidebar);
echo View::factory('default')->set('content', $content);
echo View::factory('default')->set('footer', $footer);
我尝试在显示视图中尝试“ echo”变量:
// views/default.php
echo $head;
echo $nav;
echo $header;
echo $sidebar;
echo $content;
echo $footer;
并抛出错误:
ErrorException [ 2 ]: file_put_contents(/some_path/application/logs/2011/02/23.php): failed to open stream: Permission denied ~ SYSPATH/classes/kohana/log/file.php [ 81 ]
如果我写这样的话:
// views/default.php
include Kohana::find_file('views', 'default');
显示有效;
chmod 777 /some_path/application/logs/2011/02/23.php
文件和所有目录/some_path/application/logs/
递归
UPD:
也许
// views/index.php
echo View::factory('default')
->set('head', $head)
->set('nav', $nav)
->set('header', $header)
->set('sidebar', $sidebar)
->set('content', $content)
->set('footer', $footer);
发生的情况是Kohana抛出异常并尝试记录错误,但无法保存日志文件。
确保/ application / logs可写(在某些服务器上为755或777)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.