root/trunk/system/libraries/Controller.php

Revision 2229, 1.7 kB (checked in by Shadowhand, 4 months ago)

Creating the IN_PRODUCTION flag, and access protection for module demo controllers.

  • 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 defined('SYSPATH') or die('No direct script access.');
2 /**
3  * Kohana Controller class. The controller class must be extended to work
4  * properly, so this class is defined as abstract.
5  *
6  * $Id$
7  *
8  * @package    Core
9  * @author     Kohana Team
10  * @copyright  (c) 2007-2008 Kohana Team
11  * @license    http://kohanaphp.com/license.html
12  */
13 abstract class Controller_Core {
14
15     // Allow all controllers to run in production by default
16     const ALLOW_PRODUCTION = TRUE;
17
18     /**
19      * Loads URI, and Input into this controller.
20      *
21      * @return  void
22      */
23     public function __construct()
24     {
25         if (Kohana::$instance === NULL)
26         {
27             // Set the instance to the first controller loaded
28             Kohana::$instance = $this;
29
30             // URI should always be available
31             $this->uri = new URI;
32
33             // Input should always be available
34             $this->input = new Input;
35         }
36         else
37         {
38             // URI should always be available
39             $this->uri = Kohana::$instance->uri;
40
41             // Input should always be available
42             $this->input = Kohana::$instance->input;
43         }
44     }
45
46     /**
47      * Includes a View within the controller scope.
48      *
49      * @param   string  view filename
50      * @param   array   array of view variables
51      * @return  string
52      */
53     public function _kohana_load_view($kohana_view_filename, $kohana_input_data)
54     {
55         if ($kohana_view_filename == '')
56             return;
57
58         // Buffering on
59         ob_start();
60
61         // Import the view variables to local namespace
62         extract($kohana_input_data, EXTR_SKIP);
63
64         // Views are straight HTML pages with embedded PHP, so importing them
65         // this way insures that $this can be accessed as if the user was in
66         // the controller, which gives the easiest access to libraries in views
67         include $kohana_view_filename;
68
69         // Fetch the output and close the buffer
70         return ob_get_clean();
71     }
72
73 } // End Controller Class
74
Note: See TracBrowser for help on using the browser.