admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter Application Controller Class |
| 20 | * |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 21 | * This class object is the super class the every library in |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 22 | * Code Igniter will be assigned to. |
| 23 | * |
| 24 | * @package CodeIgniter |
| 25 | * @subpackage Libraries |
| 26 | * @category Libraries |
| 27 | * @author Rick Ellis |
| 28 | * @link http://www.codeigniter.com/user_guide/general/controllers.html |
| 29 | */ |
| 30 | class Controller extends CI_Base { |
| 31 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 32 | var $_ci_scaffolding = FALSE; |
| 33 | var $_ci_scaff_table = FALSE; |
| 34 | |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 35 | |
| 36 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Constructor |
| 39 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 40 | * Calls the initialize() function |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 41 | */ |
| 42 | function Controller() |
| 43 | { |
| 44 | parent::CI_Base(); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 45 | $this->_ci_initialize(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 46 | log_message('debug', "Controller Class Initialized"); |
| 47 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 48 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 52 | * Initialize |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 53 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 54 | * Assigns all the bases classes loaded by the front controller to |
| 55 | * variables in this class. Also calls the autoload routine. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 56 | * |
| 57 | * @access private |
| 58 | * @return void |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 59 | */ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 60 | function _ci_initialize() |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 61 | { |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 62 | // Assign all the class objects that were instantiated by the |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 63 | // front controller to local class variables so that CI can be |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 64 | // run as one big super object. |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 65 | $classes = array( |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 66 | 'config' => 'Config', |
| 67 | 'input' => 'Input', |
| 68 | 'benchmark' => 'Benchmark', |
| 69 | 'uri' => 'URI', |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 70 | 'output' => 'Output', |
| 71 | 'lang' => 'Language' |
| 72 | ); |
| 73 | |
| 74 | foreach ($classes as $var => $class) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 75 | { |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame] | 76 | $this->$var =& load_class($class); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 77 | } |
admin | 4003718 | 2006-10-11 19:16:58 +0000 | [diff] [blame] | 78 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 79 | // In PHP 5 the Controller class is run as a discreet |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 80 | // class. In PHP 4 it extends the Controller |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 81 | if (floor(phpversion()) >= 5) |
| 82 | { |
| 83 | $this->load = new CI_Loader(); |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 84 | $this->load->_ci_autoloader(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 85 | } |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 86 | else |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 87 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 88 | $this->_ci_autoloader(); |
| 89 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 90 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 91 | |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 92 | // -------------------------------------------------------------------- |
| 93 | |
| 94 | /** |
| 95 | * Run Scaffolding |
| 96 | * |
| 97 | * @access private |
admin | 88a8ad1 | 2006-10-07 03:16:32 +0000 | [diff] [blame] | 98 | * @return void |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 99 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 100 | function _ci_scaffolding() |
| 101 | { |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 102 | if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) |
| 103 | { |
| 104 | show_404('Scaffolding unavailable'); |
| 105 | } |
| 106 | |
| 107 | $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); |
| 108 | |
| 109 | require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); |
| 110 | $scaff = new Scaffolding($this->_ci_scaff_table); |
| 111 | $scaff->$method(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame^] | 112 | } |
| 113 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 114 | |
| 115 | } |
| 116 | // END _Controller class |
| 117 | ?> |