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
|
|
|
|
16
|
|
|
// Allow all controllers to run in production by default |
17
|
|
|
const ALLOW_PRODUCTION = true; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Loads URI, and Input into this controller. |
21
|
|
|
* |
22
|
|
|
* @return void |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct() |
25
|
|
|
{ |
26
|
|
|
if (Kohana::$instance == null) { |
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
|
|
|
|
64
|
|
|
// Buffering on |
65
|
|
|
ob_start(); |
66
|
|
|
|
67
|
|
|
// Import the view variables to local namespace |
68
|
|
|
extract($kohana_input_data, EXTR_SKIP); |
69
|
|
|
|
70
|
|
|
// Views are straight HTML pages with embedded PHP, so importing them |
71
|
|
|
// this way insures that $this can be accessed as if the user was in |
72
|
|
|
// the controller, which gives the easiest access to libraries in views |
73
|
|
|
try { |
74
|
|
|
include $kohana_view_filename; |
75
|
|
|
} catch (Exception $e) { |
76
|
|
|
ob_end_clean(); |
77
|
|
|
throw $e; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// Fetch the output and close the buffer |
81
|
|
|
return ob_get_clean(); |
82
|
|
|
} |
83
|
|
|
} // End Controller Class |
84
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.