예제 #1
0
 /** Autload items **/
 public function autoload()
 {
     $ci = modules::$registry[$this->_class];
     /* process application autoload */
     if (!isset(self::$autoload) and self::$autoload = TRUE) {
         self::$loader->_ci_autoloader();
     }
     /* controller autoload array */
     $autoload = $ci->autoload() or $autoload = array();
     list($path, $file) = modules::find('autoload', $this->_module, 'config/');
     /* module autoload file */
     if ($path != FALSE) {
         $autoload = array_merge(modules::load_file($file, $path, 'autoload'), $autoload);
     }
     /* nothing to do? */
     if (count($autoload) == 0) {
         return;
     }
     /* autoload database & libraries */
     if (isset($autoload['libraries'])) {
         if (in_array('database', $autoload['libraries'])) {
             /* autoload database */
             if (!($db = $ci->config->item('database'))) {
                 $db['params'] = 'default';
                 $db['active_record'] = TRUE;
             }
             $ci->db = $this->database($db['params'], TRUE, $db['active_record']);
             $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
         }
         /* autoload libraries */
         foreach ($autoload['libraries'] as $library) {
             $this->library($library);
         }
     }
     /* autoload config */
     if (isset($autoload['config'])) {
         foreach ($autoload['config'] as $key => $val) {
             $this->config($val, TRUE);
         }
     }
     /* autoload helpers, plugins, scripts, languages */
     foreach (array('helper', 'plugin', 'script', 'language') as $type) {
         if (isset($autoload[$type])) {
             foreach ($autoload[$type] as $item) {
                 $this->{$type}($item);
             }
         }
     }
     /* autoload base classes */
     if (isset($autoload['class'])) {
         foreach ($autoload['class'] as $class) {
             modules::autoload($class);
         }
     }
     /* autoload models */
     if (isset($autoload['model'])) {
         foreach ($autoload['model'] as $model => $alias) {
             is_numeric($model) ? $this->model($alias) : $this->model($model, $alias);
         }
     }
     /* autoload module controllers */
     if (isset($autoload['modules']) and !in_array($this->_class, $autoload['modules'])) {
         foreach ($autoload['modules'] as $module) {
             $this->module($module);
         }
     }
 }