root/trunk/system/controllers/template.php

Revision 3700, 1.2 kB (checked in by Shadowhand, 12 days ago)

Updates to trunk:

  • Removed all SYSPATH file checks
  • Deleted some modules: code_coverage (3.0), shoutbox (defunct), user_guide (defunct), kobot (3.0), object_db (3.0)
  • Updated ORM and ORM_Iterator to match 3.0, enabling the new HABTM stuff, see r3636 and r3640
  • Property svn:eol-style set to LF
  • Property copyright set to Copyright (c) 2007 Kohana Team
  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * Allows a template to be automatically loaded and displayed. Display can be
4 * dynamically turned off in the controller methods, and the template file
5 * can be overloaded.
6 *
7 * To use it, declare your controller to extend this class:
8 * `class Your_Controller extends Template_Controller`
9 *
10 * $Id$
11 *
12 * @package    Core
13 * @author     Kohana Team
14 * @copyright  (c) 2007-2008 Kohana Team
15 * @license    http://kohanaphp.com/license.html
16 */
17abstract class Template_Controller extends Controller {
18
19    // Template view name
20    public $template = 'template';
21
22    // Default to do auto-rendering
23    public $auto_render = TRUE;
24
25    /**
26     * Template loading and setup routine.
27     */
28    public function __construct()
29    {
30        parent::__construct();
31
32        // Load the template
33        $this->template = new View($this->template);
34
35        if ($this->auto_render == TRUE)
36        {
37            // Render the template immediately after the controller method
38            Event::add('system.post_controller', array($this, '_render'));
39        }
40    }
41
42    /**
43     * Render the loaded template.
44     */
45    public function _render()
46    {
47        if ($this->auto_render == TRUE)
48        {
49            // Render the template when the class is destroyed
50            $this->template->render(TRUE);
51        }
52    }
53
54} // End Template_Controller
Note: See TracBrowser for help on using the browser.