除了davgothic的解决方案,您还可以使用Controller_Template。使用Controller_Template使其更易于管理模板&内容
class Controller_Tracer extends Controller {
public $template = 'yourtemplatefile'; // HTML template inside views folder
public function before() {
parent::before();
$this->template->title = 'My Website';
}
public function action_index() {
$this->template->content = 'Hello World';
}
public function action_trace() {
$this->template->content = View::factory('tracer');
}
}
内部的意见/ yourtemplatefile.php:
<html>
<head>
<title><?php echo isset($title) ? $title : ''; ?></title>
</head>
<body>
<h1><?php echo isset($title) ? $title : ''; ?></h1>
<?php echo isset($content) ? $content : ''; ?>
</body>
</html>
内部的意见/ tracer.php:
<p>This is tracer.</p>
<p>Nulla vitae elit libero, a pharetra augue.</p>
如果您尝试访问http://mydomain/index.php/tracer/index,您会得到:
我的网站
的Hello World
如果您尝试访问http://mydomain/index.php/tracer/trace,您将获得:
我的网站
这是示踪剂。
Nulla vitae elit libero,pharetra augue。
希望有所帮助!
您使用的是什么版本的Kohana? 3.0还是3.1? – 2011-04-15 11:58:27
我建议你检查网络服务器的响应(例如通过Firebug)。可能是它的一个5xx错误。 – biakaveron 2011-04-15 12:02:44
我正在使用3.1.2 – 2011-04-15 12:04:36