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. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter Application Controller Class |
| 20 | * |
| 21 | * This class object is the the super class the every library in |
| 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_models = array(); |
| 33 | var $_ci_scaffolding = FALSE; |
| 34 | var $_ci_scaff_table = FALSE; |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 35 | var $_ci_last_handle = NULL; |
| 36 | var $_ci_last_params = NULL; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * Loads the base classes needed to run CI, and runs the "autoload" |
| 42 | * routine which loads the systems specified in the "autoload" config file. |
| 43 | */ |
| 44 | function Controller() |
| 45 | { |
| 46 | parent::CI_Base(); |
| 47 | |
| 48 | // Assign all the class objects that were instantiated by the |
| 49 | // front controller to local class variables so that CI can be |
| 50 | // run as one big super object. |
| 51 | $this->_ci_assign_core(); |
| 52 | |
| 53 | // Load everything specified in the autoload.php file |
| 54 | $this->load->_ci_autoloader($this->_ci_autoload()); |
| 55 | |
| 56 | // This allows anything loaded using $this->load (viwes, files, etc.) |
| 57 | // to become accessible from within the Controller class functions. |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 58 | foreach (get_object_vars($this) as $key => $var) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 59 | { |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 60 | if (is_object($var)) |
| 61 | { |
| 62 | $this->load->$key =& $this->$key; |
| 63 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 64 | } |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 65 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 66 | log_message('debug', "Controller Class Initialized"); |
| 67 | } |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 68 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 69 | // -------------------------------------------------------------------- |
| 70 | |
| 71 | /** |
| 72 | * Initialization Handler |
| 73 | * |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 74 | * Designed to be called from the class files themselves. |
| 75 | * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html |
| 76 | * |
| 77 | * @access public |
| 78 | * @param string class name |
| 79 | * @param string variable name |
| 80 | * @param mixed any additional parameters |
| 81 | * @return void |
| 82 | */ |
| 83 | function init_class($class, $varname = '', $params = NULL) |
| 84 | { |
admin | 41a1685 | 2006-09-26 18:17:19 +0000 | [diff] [blame^] | 85 | // First figure out what variable we're going to assign the class to |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 86 | if ($varname == '') |
| 87 | { |
| 88 | $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); |
| 89 | } |
| 90 | |
| 91 | // Are there any parameters? |
| 92 | if ($params === NULL AND $this->_ci_last_params !== NULL) |
| 93 | { |
| 94 | $params = $this->_ci_last_params; |
| 95 | } |
| 96 | |
| 97 | // Instantiate the class |
| 98 | if ( ! is_null($params)) |
| 99 | { |
| 100 | $this->$varname = new $class($params); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | $this->$varname = new $class; |
| 105 | } |
| 106 | |
| 107 | $this->_ci_last_params = NULL; |
| 108 | $this->_ci_last_handle = NULL; |
| 109 | } |
| 110 | |
| 111 | // -------------------------------------------------------------------- |
| 112 | |
| 113 | /** |
| 114 | * Initialization Handler |
| 115 | * |
| 116 | * This function loads the requested class. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 117 | * |
| 118 | * @access private |
| 119 | * @param string the item that is being loaded |
| 120 | * @param mixed any additional parameters |
| 121 | * @return void |
| 122 | */ |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 123 | function _ci_init_class($class, $params = NULL) |
| 124 | { |
| 125 | // Prep the class name |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 126 | $class = strtolower(str_replace(EXT, '', $class)); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 127 | |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 128 | // These are used by $this->init_class() above. |
| 129 | // They lets us dynamically set the object name and pass parameters |
| 130 | $this->_ci_last_handle = $class; |
| 131 | $this->_ci_last_params = $params; |
| 132 | |
| 133 | // Does THIS file (Controller.php) contain an initialization |
| 134 | // function that maps to the requested class? |
| 135 | |
| 136 | $method = '_ci_init_'.$class; |
| 137 | |
| 138 | if (method_exists($this, $method)) |
| 139 | { |
| 140 | if (is_null($params)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 141 | { |
| 142 | $this->$method(); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | $this->$method($params); |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // We're done... |
| 150 | return TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 151 | } |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 152 | |
| 153 | // Lets search for the requested library file and load it. |
| 154 | // We'll assume that the file we load contains a call to |
| 155 | // $obj->init_class() so that the class can get instantiated. |
| 156 | // For backward compatibility we'll test for filenames that are |
| 157 | // both uppercase and lower. |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 158 | foreach (array(ucfirst($class), $class) as $filename) |
| 159 | { |
| 160 | for ($i = 1; $i < 3; $i++) |
| 161 | { |
| 162 | $path = ($i % 2) ? APPPATH : BASEPATH; |
| 163 | |
| 164 | if (file_exists($path.'libraries/'.$filename.EXT)) |
| 165 | { |
| 166 | include_once($path.'libraries/'.$filename.EXT); |
| 167 | return TRUE; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | } |
| 172 | |
| 173 | // If we got this far we were unable to find the requested class |
| 174 | log_message('error', "Unable to load the requested class: ".$class); |
| 175 | show_error("Unable to load the class: ".$class); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 176 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 177 | |
| 178 | // -------------------------------------------------------------------- |
| 179 | |
| 180 | /** |
| 181 | * Loads and instantiates the requested model class |
| 182 | * |
| 183 | * @access private |
| 184 | * @param string |
| 185 | * @return array |
| 186 | */ |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 187 | function _ci_init_model($model, $name = '', $db_conn = FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 188 | { |
| 189 | if ($name == '') |
| 190 | { |
| 191 | $name = $model; |
| 192 | } |
admin | b4473d4 | 2006-08-27 15:46:31 +0000 | [diff] [blame] | 193 | |
admin | 0d29605 | 2006-08-27 15:48:38 +0000 | [diff] [blame] | 194 | $obj =& get_instance(); |
| 195 | if (in_array($name, $obj->_ci_models)) |
admin | b4473d4 | 2006-08-27 15:46:31 +0000 | [diff] [blame] | 196 | { |
| 197 | return; |
| 198 | } |
| 199 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 200 | if (isset($this->$name)) |
| 201 | { |
| 202 | show_error('The model name you are loading is the name of a resource that is already being used: '.$name); |
| 203 | } |
| 204 | |
| 205 | $model = strtolower($model); |
| 206 | |
| 207 | if ( ! file_exists(APPPATH.'models/'.$model.EXT)) |
| 208 | { |
| 209 | show_error('Unable to locate the model you have specified: '.$model); |
| 210 | } |
| 211 | |
| 212 | if ($db_conn !== FALSE) |
| 213 | { |
| 214 | if ($db_conn === TRUE) |
| 215 | $db_conn = ''; |
| 216 | |
| 217 | $this->_ci_init_database($db_conn, FALSE, TRUE); |
| 218 | } |
| 219 | |
| 220 | if ( ! class_exists('Model')) |
| 221 | { |
| 222 | require_once(BASEPATH.'libraries/Model'.EXT); |
| 223 | } |
| 224 | |
| 225 | require_once(APPPATH.'models/'.$model.EXT); |
| 226 | |
| 227 | $model = ucfirst($model); |
| 228 | $this->$name = new $model(); |
| 229 | $this->_ci_models[] = $name; |
| 230 | $this->_ci_assign_to_models(); |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 231 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 232 | |
| 233 | // -------------------------------------------------------------------- |
| 234 | |
| 235 | /** |
| 236 | * Assign to Models |
| 237 | * |
| 238 | * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) |
| 239 | * will be available to modles, if any exist. |
| 240 | * |
| 241 | * @access public |
| 242 | * @param object |
| 243 | * @return array |
| 244 | */ |
| 245 | function _ci_assign_to_models() |
| 246 | { |
| 247 | $obj =& get_instance(); |
| 248 | if (count($obj->_ci_models) == 0) |
| 249 | { |
| 250 | return; |
| 251 | } |
| 252 | foreach ($obj->_ci_models as $model) |
| 253 | { |
| 254 | $obj->$model->_assign_libraries(); |
| 255 | } |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 256 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 257 | |
| 258 | // -------------------------------------------------------------------- |
| 259 | |
| 260 | /** |
| 261 | * Auto-initialize Core Classes |
| 262 | * |
| 263 | * This initializes the core systems that are specified in the |
| 264 | * libraries/autoload.php file, as well as the systems specified in |
| 265 | * the $autoload class array above. |
| 266 | * |
| 267 | * It returns the "autoload" array so we can pass it to the Loader |
| 268 | * class since it needs to autoload plugins and helper files |
| 269 | * |
| 270 | * The config/autoload.php file contains an array that permits |
| 271 | * sub-systems to be loaded automatically. |
| 272 | * |
| 273 | * @access private |
| 274 | * @return array |
| 275 | */ |
| 276 | function _ci_autoload() |
| 277 | { |
| 278 | include_once(APPPATH.'config/autoload'.EXT); |
| 279 | |
| 280 | if ( ! isset($autoload)) |
| 281 | { |
| 282 | return FALSE; |
| 283 | } |
| 284 | |
| 285 | if (count($autoload['config']) > 0) |
| 286 | { |
| 287 | foreach ($autoload['config'] as $key => $val) |
| 288 | { |
| 289 | $this->config->load($val); |
| 290 | } |
| 291 | } |
| 292 | unset($autoload['config']); |
| 293 | |
admin | d48ef1c | 2006-09-21 06:22:05 +0000 | [diff] [blame] | 294 | // A little tweak to remain backward compatible |
| 295 | // The $autoload['core'] item was deprecated |
| 296 | if ( ! isset($autoload['libraries'])) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 297 | { |
admin | d48ef1c | 2006-09-21 06:22:05 +0000 | [diff] [blame] | 298 | $autoload['libraries'] = $autoload['core']; |
| 299 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 300 | } |
| 301 | |
admin | 6e00bab | 2006-09-26 08:13:06 +0000 | [diff] [blame] | 302 | $exceptions = array('dbutil', 'dbexport'); |
| 303 | |
admin | d48ef1c | 2006-09-21 06:22:05 +0000 | [diff] [blame] | 304 | foreach ($autoload['libraries'] as $item) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 305 | { |
admin | 6e00bab | 2006-09-26 08:13:06 +0000 | [diff] [blame] | 306 | if ( ! in_array($item, $exceptions)) |
| 307 | { |
| 308 | $this->_ci_init_class($item); |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | $this->_ci_init_dbextra($item); |
| 313 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 314 | } |
admin | d48ef1c | 2006-09-21 06:22:05 +0000 | [diff] [blame] | 315 | unset($autoload['libraries']); |
| 316 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 317 | return $autoload; |
| 318 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 319 | |
| 320 | // -------------------------------------------------------------------- |
| 321 | |
| 322 | /** |
| 323 | * Assign the core classes to the global $CI object |
| 324 | * |
| 325 | * By assigning all the classes instantiated by the front controller |
| 326 | * local class variables we enable everything to be accessible using |
| 327 | * $this->class->function() |
| 328 | * |
| 329 | * @access private |
| 330 | * @return void |
| 331 | */ |
| 332 | function _ci_assign_core() |
| 333 | { |
| 334 | foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) |
| 335 | { |
| 336 | $class = strtolower($val); |
| 337 | $this->$class =& _load_class('CI_'.$val); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | $this->lang =& _load_class('CI_Language'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 341 | |
| 342 | // In PHP 4 the Controller class is a child of CI_Loader. |
| 343 | // In PHP 5 we run it as its own class. |
| 344 | if (floor(phpversion()) >= 5) |
| 345 | { |
| 346 | $this->load = new CI_Loader(); |
| 347 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 348 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 349 | |
| 350 | // -------------------------------------------------------------------- |
| 351 | |
| 352 | /** |
| 353 | * Initialize Scaffolding |
| 354 | * |
| 355 | * This initializing function works a bit different than the |
| 356 | * others. It doesn't load the class. Instead, it simply |
| 357 | * sets a flag indicating that scaffolding is allowed to be |
| 358 | * used. The actual scaffolding function below is |
| 359 | * called by the front controller based on whether the |
| 360 | * second segment of the URL matches the "secret" scaffolding |
| 361 | * word stored in the application/config/routes.php |
| 362 | * |
| 363 | * @access private |
| 364 | * @param string the table to scaffold |
| 365 | * @return void |
| 366 | */ |
| 367 | function _ci_init_scaffolding($table = FALSE) |
| 368 | { |
| 369 | if ($table === FALSE) |
| 370 | { |
| 371 | show_error('You must include the name of the table you would like access when you initialize scaffolding'); |
| 372 | } |
| 373 | |
| 374 | $this->_ci_scaffolding = TRUE; |
| 375 | $this->_ci_scaff_table = $table; |
| 376 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 377 | |
| 378 | // -------------------------------------------------------------------- |
| 379 | |
| 380 | /** |
| 381 | * Initialize Database |
| 382 | * |
| 383 | * @access private |
| 384 | * @param mixed database connection values |
| 385 | * @param bool whether to return the object for multiple connections |
| 386 | * @return void |
| 387 | */ |
| 388 | function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 389 | { |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 390 | if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) |
| 391 | { |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | // Load the DB config file if needed |
| 396 | if (is_string($params) AND strpos($params, '://') === FALSE) |
| 397 | { |
| 398 | include(APPPATH.'config/database'.EXT); |
| 399 | |
| 400 | $group = ($params == '') ? $active_group : $params; |
| 401 | |
| 402 | if ( ! isset($db[$group])) |
| 403 | { |
| 404 | show_error('You have specified an invalid database connection group: '.$group); |
| 405 | } |
| 406 | |
| 407 | $params = $db[$group]; |
| 408 | } |
| 409 | |
| 410 | // No DB specified yet? Beat them senseless... |
| 411 | if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') |
| 412 | { |
| 413 | show_error('You have not selected a database type to connect to.'); |
| 414 | } |
| 415 | |
| 416 | // Load the DB classes. Note: Since the active record class is optional |
| 417 | // we need to dynamically create a class that extends proper parent class |
| 418 | // based on whether we're using the active record class or not. |
| 419 | // Kudos to Paul for discovering this clever use of eval() |
| 420 | |
| 421 | if ($active_record == TRUE) |
| 422 | { |
| 423 | $params['active_r'] = TRUE; |
| 424 | } |
| 425 | |
admin | 5808346 | 2006-09-24 17:58:27 +0000 | [diff] [blame] | 426 | require_once(BASEPATH.'database/DB_driver'.EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 427 | |
| 428 | if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) |
| 429 | { |
admin | c9a8bab | 2006-09-24 20:28:33 +0000 | [diff] [blame] | 430 | require_once(BASEPATH.'database/DB_active_rec'.EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 431 | |
| 432 | if ( ! class_exists('CI_DB')) |
| 433 | { |
| 434 | eval('class CI_DB extends CI_DB_active_record { }'); |
| 435 | } |
| 436 | } |
| 437 | else |
| 438 | { |
| 439 | if ( ! class_exists('CI_DB')) |
| 440 | { |
| 441 | eval('class CI_DB extends CI_DB_driver { }'); |
| 442 | } |
| 443 | } |
admin | c1fa074 | 2006-09-21 23:50:23 +0000 | [diff] [blame] | 444 | |
admin | 46563d5 | 2006-09-24 18:14:22 +0000 | [diff] [blame] | 445 | require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 446 | |
| 447 | // Instantiate the DB adapter |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 448 | $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 449 | $DB = new $driver($params); |
| 450 | |
| 451 | if ($return === TRUE) |
| 452 | { |
| 453 | return $DB; |
| 454 | } |
| 455 | |
| 456 | $obj =& get_instance(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 457 | $obj->db =& $DB; |
| 458 | } |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 459 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 460 | // -------------------------------------------------------------------- |
| 461 | |
| 462 | /** |
admin | 6e00bab | 2006-09-26 08:13:06 +0000 | [diff] [blame] | 463 | * Initialize Database Ancillary Classes |
| 464 | * |
| 465 | * @access private |
| 466 | * @param str class name |
| 467 | * @return void |
| 468 | */ |
| 469 | function _ci_init_dbextra($class) |
| 470 | { |
| 471 | $map = array('dbutil' => 'DB_utility', 'dbexport' => 'DB_export'); |
| 472 | require_once(BASEPATH.'database/'.$map[$class].EXT); |
| 473 | |
| 474 | $this->init_class('CI_'.$map[$class], $class); |
| 475 | } |
| 476 | |
| 477 | // -------------------------------------------------------------------- |
| 478 | |
| 479 | /** |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 480 | * Returns TRUE if a class is loaded, FALSE if not |
| 481 | * |
| 482 | * @access public |
| 483 | * @param string the class name |
| 484 | * @return bool |
| 485 | */ |
| 486 | function _ci_is_loaded($class) |
| 487 | { |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 488 | return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 489 | } |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 490 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 491 | // -------------------------------------------------------------------- |
| 492 | |
| 493 | /** |
| 494 | * Scaffolding |
| 495 | * |
| 496 | * Initializes the scaffolding. |
| 497 | * |
| 498 | * @access private |
| 499 | * @return void |
| 500 | */ |
| 501 | function _ci_scaffolding() |
| 502 | { |
| 503 | if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) |
| 504 | { |
| 505 | show_404('Scaffolding unavailable'); |
| 506 | } |
| 507 | |
| 508 | if (class_exists('Scaffolding')) return; |
| 509 | |
| 510 | if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'))) |
| 511 | { |
| 512 | $method = 'view'; |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | $method = $this->uri->segment(3); |
| 517 | } |
| 518 | |
| 519 | $this->_ci_init_database("", FALSE, TRUE); |
admin | 7981a9a | 2006-09-26 07:52:09 +0000 | [diff] [blame] | 520 | $this->_ci_init_class('pagination'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 521 | require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); |
| 522 | $this->scaff = new Scaffolding($this->_ci_scaff_table); |
| 523 | $this->scaff->$method(); |
| 524 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 525 | |
| 526 | } |
| 527 | // END _Controller class |
| 528 | ?> |