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 | |
| 35 | /** |
| 36 | * Constructor |
| 37 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 38 | * Calls the initialize() function |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 39 | */ |
| 40 | function Controller() |
| 41 | { |
| 42 | parent::CI_Base(); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 43 | $this->_ci_initialize(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | log_message('debug', "Controller Class Initialized"); |
| 45 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 46 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 47 | // -------------------------------------------------------------------- |
| 48 | |
| 49 | /** |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 50 | * Initialize |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 51 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 52 | * Assigns all the bases classes loaded by the front controller to |
| 53 | * variables in this class. Also calls the autoload routine. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 54 | * |
| 55 | * @access private |
| 56 | * @return void |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 57 | */ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 58 | function _ci_initialize() |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 59 | { |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 60 | // Assign all the class objects that were instantiated by the |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 61 | // front controller to local class variables so that CI can be |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 62 | // run as one big super object. |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 63 | $classes = array( |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 64 | 'config' => 'Config', |
| 65 | 'input' => 'Input', |
| 66 | 'benchmark' => 'Benchmark', |
| 67 | 'uri' => 'URI', |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 68 | 'output' => 'Output', |
| 69 | 'lang' => 'Language' |
| 70 | ); |
| 71 | |
| 72 | foreach ($classes as $var => $class) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 73 | { |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame] | 74 | $this->$var =& load_class($class); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 75 | } |
admin | 4003718 | 2006-10-11 19:16:58 +0000 | [diff] [blame] | 76 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 77 | // In PHP 5 the Controller class is run as a discreet |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 78 | // class. In PHP 4 it extends the Controller |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 79 | if (floor(phpversion()) >= 5) |
| 80 | { |
| 81 | $this->load = new CI_Loader(); |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 82 | $this->load->_ci_autoloader(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 83 | } |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 84 | else |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 85 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 86 | $this->_ci_autoloader(); |
| 87 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 88 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 89 | |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 90 | // -------------------------------------------------------------------- |
| 91 | |
| 92 | /** |
| 93 | * Run Scaffolding |
| 94 | * |
| 95 | * @access private |
admin | 88a8ad1 | 2006-10-07 03:16:32 +0000 | [diff] [blame] | 96 | * @return void |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 97 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 98 | function _ci_scaffolding() |
| 99 | { |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 100 | if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) |
| 101 | { |
| 102 | show_404('Scaffolding unavailable'); |
| 103 | } |
| 104 | |
| 105 | $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); |
| 106 | |
| 107 | require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); |
| 108 | $scaff = new Scaffolding($this->_ci_scaff_table); |
| 109 | $scaff->$method(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 110 | } |
| 111 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 112 | |
| 113 | } |
| 114 | // END _Controller class |
| 115 | ?> |