【问题标题】:Templates In Kohana 3.1Kohana 3.1 中的模板
【发布时间】:2011-09-08 21:03:30
【问题描述】:

我在几个月前使用过它们。然后我切换到燃料。然后我切换回了 Kohana。

问题?我忘记了如何正确使用模板(我的意思是Controller_Template)。 Kohana 的文档中有 tutorials,但现在链接似乎已损坏。

请提醒我如何使用它们!

【问题讨论】:

  • 一段时间过去了,但您帖子中的一件事对我来说很有趣。你为什么从 Fuel 切换到 Kohana?
  • 另一个有趣的问题是为什么要尝试 Fuel?
  • 好吧,我想尝试所有可能的工具……我想了解它们!例如,我现在正在使用 Python。 :)

标签: templates view kohana kohana-3


【解决方案1】:
$template = 'mytemplate';

function action_index() {
      $template->content = new View("content");
      $template->content->title = "page title"; // depends on the fields in your view
}

这将要求 mytemplate.php 和 content.php 视图文件存在

【讨论】:

    【解决方案2】:

    如果你真的想使用它们,你必须扩展Kohana_Template。然后你会为你的视图名称设置一个公共字段'$template',然后只需执行 $this->template->foo = "foo" 在模板上设置变量

    public class Controller_MyController extends Controller_Template
    {
        public $template = "my_view";
        public function action_foo()
        {
            $this->template->foo = "foo"
        }
    }
    

    但核心开发人员不鼓励人们使用它。您最好使用某种模板引擎,例如Kostache 来构建您的模板。

    【讨论】:

    • 只是好奇,如果不鼓励使用,为什么还要包含它?
    • 因为我猜有些人还在使用它。不过不确定。
    猜你喜欢
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 2011-10-22
    • 1970-01-01
    相关资源
    最近更新 更多