Kohana 3.3.1中Controller和Controller_Template的区别

官方文档实在是语焉不详,因为Kohana起源于CI,而CI中并没有Controller_Template这个东西,顿时有些摸不着头脑。

然后查看了Kohana-v3.3.1/system/classes/Kohana/Controller/Template.php之后总算明白了,Controller_Template继承自Controller,然后只是多了将$template指向的view自动render()的功能(在成员函数::after()中)。

<?php defined(‘SYSPATH’) OR die(‘No direct script access.’);
/**

  • Abstract controller class for automatic templating.
    *
  • @package Kohana
  • @category Controller
  • @author Kohana Team
  • @copyright (c) 2008-2012 Kohana Team
  • @license http://kohanaframework.org/license
    */
    abstract class Kohana_Controller_Template extends Controller {

    /**

    • @var View page template
      */
      public $template = ‘template’;

      /**

    • @var boolean auto render template
      **/
      public $auto_render = TRUE;

      /**

    • Loads the template [View] object.
      */
      public function before()
      {
      parent::before();

      if ($this->auto_render === TRUE)
      {

       // Load the template
       $this-&gt;template = View::factory($this-&gt;template);
      

      }
      }

      /**

    • Assigns the template [View] as the request response.
      */
      public function after()
      {
      if ($this->auto_render === TRUE)
      {

       $this-&gt;response-&gt;body($this-&gt;template-&gt;render());
      

      }

      parent::after();
      }

}