Initial Kohana install
[speedfreak] / Server / system / libraries / Controller.php
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
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: Controller.php 4365 2009-05-27 21:09:27Z samsoir $
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
31                 // URI should always be available
32                 $this->uri = URI::instance();
33
34                 // Input should always be available
35                 $this->input = Input::instance();
36         }
37
38         /**
39          * Handles methods that do not exist.
40          *
41          * @param   string  method name
42          * @param   array   arguments
43          * @return  void
44          */
45         public function __call($method, $args)
46         {
47                 // Default to showing a 404 page
48                 Event::run('system.404');
49         }
50
51         /**
52          * Includes a View within the controller scope.
53          *
54          * @param   string  view filename
55          * @param   array   array of view variables
56          * @return  string
57          */
58         public function _kohana_load_view($kohana_view_filename, $kohana_input_data)
59         {
60                 if ($kohana_view_filename == '')
61                         return;
62
63                 // Buffering on
64                 ob_start();
65
66                 // Import the view variables to local namespace
67                 extract($kohana_input_data, EXTR_SKIP);
68
69                 // Views are straight HTML pages with embedded PHP, so importing them
70                 // this way insures that $this can be accessed as if the user was in
71                 // the controller, which gives the easiest access to libraries in views
72                 try
73                 {
74                         include $kohana_view_filename;
75                 }
76                 catch (Exception $e)
77                 {
78                         ob_end_clean();
79                         throw $e;
80                 }
81
82                 // Fetch the output and close the buffer
83                 return ob_get_clean();
84         }
85
86 } // End Controller Class