CI フレームワーク ローダー Loader.php ソース コード分析、ciloader.php_PHP チュートリアル

WBOY
リリース: 2016-07-13 10:15:06
オリジナル
923 人が閲覧しました

CI フレームワーク ローダー Loader.php ソース コード分析、ciloader.php

その名前が示すように、ローダーは CI を使用するときに要素をロードします:

$this->load->library()
$this->load->view()
$this->load->model()
$this->load->database()
$this->load->helper()
$this->load->config()
$this->load->add_package_path()

コードをコピーします コードは次のとおりです:

/**
* ローダークラス
*
* ユーザーがビューとファイルをロードする一般的な関数には、model()、view()、library()、helper() があります
*
* コントローラーの優れたアシスタントである $this->load =&load_class('Loader', 'core'); ローダーがロードされると、コントローラーは非常に強力になります
​*/
クラス CI_Loader {
 保護された $_ci_ob_level;
 protected $_ci_view_paths = array();
 protected $_ci_library_paths = array();
 protected $_ci_model_paths = array();
 protected $_ci_helper_paths = array();
 protected $_base_classes = array(); // コントローラークラスで設定
 protected $_ci_cached_vars = array();
 protected $_ci_classes = array();
 protected $_ci_loaded_files = array();
 
 protected $_ci_models = array();
 protected $_ci_helpers = array();
 protected $_ci_varmap = array('unit_test' => 'unit',
           'user_agent' => 「エージェント」);
 パブリック関数 __construct()
 {
                //获取缓冲嵌套级别
  $this->_ci_ob_level = ob_get_level();
  //ライブラリ経路
                $this->_ci_library_paths = array(APPPATH, BASEPATH);
                //ヘルパー経路
  $this->_ci_helper_paths = array(APPPATH, BASEPATH);
                //モデル径
  $this->_ci_model_paths = array(APPPATH);
                //ビュー経路
  $this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
  log_message('debug', "ローダー クラスが初期化されました");
 }
 // ------------------------------------------------ --------------------
 /**
* ローダーの初期化
*
​*/
 パブリック関数initialize()
 {
  $this->_ci_classes = array();
  $this->_ci_loaded_files = array();
  $this->_ci_models = array();
                // 将is_loaded(共通中记录追加ダウンロード核心类関数数)追加された核心类交给_base_classes
  $this->_base_classes =& is_loaded();
                //追加autoload.php構成中文件
  $this->_ci_autoloader();
  $this を返します;
 }
 // ------------------------------------------------ --------------------
 /**
* クラスがロードされているかどうかを確認してください
​*/
 パブリック関数 is_loaded($class)
 {
  if (isset($this->_ci_classes[$class]))
  {
   return $this->_ci_classes[$class];
  }
  FALSE を返します;
 }
 // ------------------------------------------------ --------------------
 /**
* ロードクラス
​*/
 パブリック関数ライブラリ($library = '', $params = NULL, $object_name = NULL)
 {
  if (is_array($library))
  {
   foreach ($library を $class として)
   {
    $this->library($class, $params);
   }
   戻ります;
  }
                //$library が空であるか、すでにダウンロードされている場合。。。
  if ($library == '' OR isset($this->_base_classes[$library]))
  {
   FALSE を返します;
  }
  if ( ! is_null($params) && ! is_array($params))
  {
   $params = NULL;
  }
  $this->_ci_load_class($library, $params, $object_name);
 }
 // ------------------------------------------------ --------------------
 /**
* モデルをロードしてインスタンス化します
​*/
 パブリック関数モデル($model, $name = '', $db_conn = FALSE)
 {
                //CIサポート数組追加多数モデル
  if (is_array($model))
  {
   foreach ($model として $babe)
   {
    $this->モデル($babe);
   }
   戻ります;
  }
  if ($model == '')
  {
   戻ります;
  }
  $path = '';
  // 有無子目录
  if (($last_slash = strrpos($model, '/')) !== FALSE)
  {
   // パスは最後のスラッシュの前にあります
   $path = substr($model, 0, $last_slash + 1);
   // そしてその後ろにあるモデル名
   $model = substr($model, $last_slash + 1);
  }
  if ($name == '')
  {
   $name = $model;
  }
  if (in_array($name, $this->_ci_models, TRUE))
  {
   戻ります;
  }
  $CI =& get_instance();
  if (isset($CI->$name))
  {
   show_error('ロードしているモデル名は、すでに使用されているリソースの名前です: '.$name);
  }
  $model = strto lower($model); //モデル文件名全小写
  foreach ($this->_ci_model_paths as $mod_path)
  {
   if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
   {
    続けます;
   }
   if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
   {
    if ($db_conn === TRUE)
    {
     $db_conn = '';
    }
    $CI->load->database($db_conn, FALSE, TRUE);
   }
   if ( ! class_exists('CI_Model'))
   {
    load_class('モデル', 'コア');
   }
   require_once($mod_path.'models/'.$path.$model.'.php');
   $model = ucfirst($model);
   $CI->$name = 新しい $model();
                        //Loader::_ci_models 内に存在し、後でそれを使用して、特定のモデルが既にロードされているかどうかを判断できます。    $this->_ci_models[] = $name;
   戻ります;
  }
  // モデルが見つかりませんでした
  show_error('指定したモデルが見つかりません: '.$model);
 }
 // ------------------------------------------------ --------------------
 /**
* データベースローダー
​*/
 パブリック関数データベース($params = ''、$return = FALSE、$active_record = NULL)
 {
  // スーパーオブジェクトをつかみます
  $CI =& get_instance();
  // 追加dbdb
が必要かどうか   if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
  {
   FALSE を返します;
  }
  require_once(BASEPATH.'database/DB.php');
  if ($return === TRUE)
  {
   return DB($params, $active_record);
  }
  // db 変数を初期化します。  予防するために必要です
  // 一部の設定での参照エラー
  $CI->db = '';
  // DBクラスをロードします
  $CI->db =& DB($params, $active_record);
 }
 // ------------------------------------------------ --------------------
 /**
* データベースツールクラスをロード
​*/
 パブリック関数 dbutil()
 {
  if ( ! class_exists('CI_DB'))
  {
   $this->database();
  }
  $CI =& get_instance();
  // 下位互換性のために、dbforge をロードして、dbutils を拡張できるようにします
  // この使用は非推奨であり、強く推奨されません
  $CI->load->dbforge();
  require_once(BASEPATH.'database/DB_utility.php');
  require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
  $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
  $CI->dbutil = 新しい $class();
 }
 // ------------------------------------------------ --------------------
 /**
  * Database Forge クラスをロードします
  *
  * @return 文字列
 */
 パブリック関数 dbforge()
 {
  if ( ! class_exists('CI_DB'))
  {
   $this->database();
  }
  $CI =& get_instance();
  require_once(BASEPATH.'database/DB_forge.php');
  require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
  $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
  $CI->dbforge = 新しい $class();
 }
 // ------------------------------------------------ --------------------
 /**
* ビューファイルをロードします
​*/
 public function view($view, $vars = array(), $return = FALSE)
 {
  return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
 }
 // ------------------------------------------------ --------------------
 /**
* 通常のファイルをロードします
​*/
 パブリック関数ファイル($path, $return = FALSE)
 {
  return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
 }
 // ------------------------------------------------ --------------------
 /**
  * 設置变量
  *
  * 変数を設定すると、以下で使用できるようになります
  * コントローラークラスとその「ビュー」ファイル
  *
 */
 パブリック関数 vars($vars = array(), $val = '')
 {
  if ($val != '' AND is_string($vars))
  {
   $vars = array($vars => $val);
  }
  $vars = $this->ci_object_to_array($vars);
  if (is_array($vars) AND count($vars) > 0)
  {
   foreach ($vars as $key => $val)
   {
    $this->_ci_cached_vars[$key] = $val;
   }
  }
 }
 // ------------------------------------------------ --------------------
 /**
* 変数を確認して取得します
​*/
 パブリック関数 get_var($key)
 {
  return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
 }
 // ------------------------------------------------ --------------------
 /**
* ロードヘルパー
​*/
 パブリック関数ヘルパー($helpers = array())
 {
  foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
  {
   if (isset($this->_ci_helpers[$helper]))
   {
    続けます;
   }
   $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
   // 結果が扩展ヘルパーの话
   if (file_exists($ext_helper))
   {
    $base_helper = BASEPATH.'helpers/'.$helper.'.php';
    if ( ! file_exists($base_helper))
    {
     show_error('要求されたファイルをロードできません: helpers/'.$helper.'.php');
    }
    include_once($ext_helper);
    include_once($base_helper);
    $this->_ci_helpers[$helper] = TRUE;
    log_message('debug', 'ヘルパーがロードされました: '.$helper);
    続けます;
   }
   // 結果不是扩展helper,helper路径中加下helper
   foreach ($this->_ci_helper_paths を $path として)
   {
    if (file_exists($path.'helpers/'.$helper.'.php'))
    {
     include_once($path.'helpers/'.$helper.'.php');
     $this->_ci_helpers[$helper] = TRUE;
     log_message('debug', 'ヘルパーがロードされました: '.$helper);
     休憩;
    }
   }
   // このヘルパーが正常にダウンロードできなかった場合は、ダウンロードヘルパーが失敗したことを示します
   if ( ! isset($this->_ci_helpers[$helper]))
   {
    show_error('要求されたファイルをロードできません: helpers/'.$helper.'.php');
   }
  }
 }
 // ------------------------------------------------ --------------------
 /**
* ヘルパーの呼び出しも上記のヘルパーであることがわかりますが、これは単なるヘルパーのエイリアスです
​*/
 パブリック関数ヘルパー($helpers = array())
 {
  $this->helper($helpers);
 }
 // ------------------------------------------------ --------------------
 /**
* 言語ファイルをロードします
​*/
 パブリック関数言語($file = array(), $lang = '')
 {
  $CI =& get_instance();
  if ( ! is_array($file))
  {
   $file = 配列($file);
  }
  foreach ($file を $langfile として)
  {
   $CI->lang->load($langfile, $lang);
  }
 }
 // ------------------------------------------------ --------------------
 /**
* 設定ファイルをロードします
​*/
 public function config($file = '', $use_sections = FALSE, $fail_graceful = FALSE)
 {
  $CI =& get_instance();
  $CI->config->load($file, $use_sections, $fail_graceful);
 }
 // ------------------------------------------------ --------------------
 /**
*ドライバー
*
* ドライバーライブラリをロードします
​*/
 パブリック関数ドライバー($library = ''、$params = NULL、$object_name = NULL)
 {
  if ( ! class_exists('CI_Driver_Library'))
  {
   // ここではオブジェクトをインスタンス化していません。これはライブラリ自体によって行われます
   BASEPATH.'libraries/Driver.php';
が必要です   }
  if ($library == '')
  {
   FALSE を返します;
  }
  // ドライバーは *常に* サブフォルダー内にあるため、ローダーをしばらく保存できます
  // 通常はライブラリと同じ名前が付けられます
  if ( ! strpos($library, '/'))
  {
   $library = ucfirst($library).'/'.$library;
  }
  return $this->library($library, $params, $object_name);
 }
 // ------------------------------------------------ --------------------
 /**
* パッケージパスを追加
*
* パッケージパスをライブラリ、モデル、アシスタント、構成パスに追加します
​*/
 パブリック関数 add_package_path($path, $view_cascade=TRUE)
 {
  $path = rtrim($path, '/').'/';
  array_unshift($this->_ci_library_paths, $path);
  array_unshift($this->_ci_model_paths, $path);
  array_unshift($this->_ci_helper_paths, $path);
  $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
  $config =& $this->_ci_get_component('config');
  array_unshift($config->_config_paths, $path);
 }
 // ------------------------------------------------ --------------------
 /**
* パッケージパスを取得します。デフォルトでは BASEPATH は含まれません
​*/
 パブリック関数 get_package_paths($include_base = FALSE)
 {
  return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
 }
 // ------------------------------------------------ --------------------
 /**
  *剔除パッケージパス
  *
  * ライブラリ、モデル、ヘルパー パス配列にパスが存在する場合は、それを削除します
  * パスが指定されていない場合は、最後に追加されたパスが削除されます。
  *
 */
 パブリック関数remove_package_path($path = '', $remove_config_path = TRUE)
 {
  $config =& $this->_ci_get_component('config');
  if ($path == '')
  {
   $void = array_shift($this->_ci_library_paths);
   $void = array_shift($this->_ci_model_paths);
   $void = array_shift($this->_ci_helper_paths);
   $void = array_shift($this->_ci_view_paths);
   $void = array_shift($config->_config_paths);
  }
  それ以外
  {
   $path = rtrim($path, '/').'/';
   foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
   {
    if (($key = array_search($path, $this->{$var})) !== FALSE)
    {
     unset($this->{$var}[$key]);
    }
   }
   if (isset($this->_ci_view_paths[$path.'views/']))
   {
    unset($this->_ci_view_paths[$path.'views/']);
   }
   if (($key = array_search($path, $config->_config_paths)) !== FALSE)
   {
    unset($config->_config_paths[$key]);
   }
  }
  // 保護用の経路依然存在します
  $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
  $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
  $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
  $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
  $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
 }
 // ------------------------------------------------ --------------------
 /**
  *ローダー
  *
  * この関数はビューとファイルをロードするために使用されます。
  * シンボルとの衝突を避けるために、変数には _ci_ という接頭辞が付けられます
  * ファイルの表示に使用できる変数
  *
  * @param配列
  * @return void
 */
 保護された関数 _ci_load($_ci_data)
 {
  // デフォルトのデータ変数を設定します
  foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
  {
   $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
  }
  $file_exists = FALSE;
                //$_ci_path が空でない場合は、現在ダウンロードされる通常のファイルが示されます。Loader::file にはパスが含まれます
  if ($_ci_path != '')
  {
   $_ci_x =explode('/', $_ci_path);
   $_ci_file = end($_ci_x);
  }
  それ以外
  {
   $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
   $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;
   foreach ($this->ci_view_paths as $view_file =>$cascade)
   {
    if (file_exists($view_file.$_ci_file))
    {
     $_ci_path = $view_file.$_ci_file;
     $file_exists = TRUE;
     休憩;
    }
    if ( ! $cascade)
    {
     休憩;
    }
   }
  }
                //view文件不存在则会报错
  if ( ! $file_exists && ! file_exists($_ci_path))
  {
   show_error('要求されたファイルをロードできません: '.$_ci_file);
  }
  // CI のすべてのプロパティを保持します   $_ci_CI =& get_instance();
  foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
  {
   if ( ! isset($this->$_ci_key))
   {
    $this->$_ci_key =& $_ci_CI->$_ci_key;
   }
  }
  /*
   * 変数を抽出してキャッシュします
   *
   * 専用の $this->load_vars() を使用して変数を設定することもできます
   * 関数を使用するか、この関数の 2 番目のパラメーターを使用します。合併します
   * 2 つのタイプをキャッシュし、その中に埋め込まれたビューが保存されるようにします
   * 他のビューはこれらの変数にアクセスできます。
   */
  if (is_array($_ci_vars))
  {
   $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
  }
  extract($this->_ci_cached_vars);
  /*
   * 映像コンテンツを缓存区に放流
   *
   */
  ob_start();
  // 短标签
をサポートします   if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
  {
   echo eval('?>'.preg_replace("/;*s*?>/", "; ?>", str_replace('   }
  それ以外
  {
   include($_ci_path); // include() と include_once() では、同じ名前の複数のビューが許可されます
  }
  log_message('debug', 'ロードされたファイル: '.$_ci_path);
  // 否かはビューデータを直接返します
  if ($_ci_return === TRUE)
  {
   $buffer = ob_get_contents();
   @ob_end_clean();
   $buffer を返します;
  }
  //現在のこの動画ファイルは別の動画ファイルによって $this->view() メソッドによって取り込まれており、つまり動画ファイルが動画ファイルに挿入されています
  if (ob_get_level() > $this->_ci_ob_level + 1)
  {
   ob_end_flush();
  }
  それ以外
  { //// 圧縮領域のコンテンツを出力コンポーネントに渡し、圧縮領域をクリアします。
   $_ci_CI->output->append_output(ob_get_contents());
   @ob_end_clean();
  }
 }
 // ------------------------------------------------ --------------------
 /**
* クラスを読み込み中
​*/
 保護された関数 _ci_load_class($class, $params = NULL, $object_name = NULL)
 {
  // 去掉.php および両端の/获取的 $class は类名または目录名+类名
  $class = str_replace('.php', '', Trim($class, '/'));
  // CI允许dir/filename方式
  $subdir = '';
  if (($last_slash = strrpos($class, '/')) !== FALSE)
  {
   // 目录
   $subdir = substr($class, 0, $last_slash + 1);
   // 文章名
   $class = substr($class, $last_slash + 1);
  }
  // 允许追加ダウンロードの类名首字母大写または全小写
  foreach (array(ucfirst($class), strto lower($class)) as $class)
  {
   $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
   // 是否是扩展类
   if (file_exists($subclass))
   {
    $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
    if ( ! file_exists($baseclass))
    {
     log_message('error', "要求されたクラスをロードできません: ".$class);
     show_error("要求されたクラスをロードできません: ".$class);
    }
    // 安全性: クラスは前の呼び出しによってすでにロードされていますか?
    if (in_array($subclass, $this->_ci_loaded_files))
    {
     // これが重複したリクエストであると判断する前に、見てみましょう
     // カスタム オブジェクト名が指定されている場合。  もしそうなら、そうします
     // オブジェクトの新しいインスタンスを返します
     if ( ! is_null($object_name))
     {
      $CI =& get_instance();
      if ( ! isset($CI->$object_name))
      {
       return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
      }
     }
     $is_duplicate = TRUE;
     log_message('debug', $class." クラスはすでにロードされています。2 回目の試行は無視されました。");
     戻ります;
    }
    include_once($baseclass);
    include_once($subclass);
    $this->_ci_loaded_files[] = $subclass;
                                //实例化
    return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
   }
   // 如果不是扩展,和上面类似
   $is_duplicate = FALSE;
   foreach ($this->_ci_library_paths as $path)
   {
    $filepath = $path.'libraries/'.$subdir.$class.'.php';
    // ファイルは存在しますか?  いいえ?  残念…
    if ( ! file_exists($filepath))
    {
     続けます;
    }
    // 安全性: クラスは前の呼び出しによってすでにロードされていますか?
    if (in_array($filepath, $this->_ci_loaded_files))
    {
     // これが重複したリクエストであると判断する前に、見てみましょう
     // カスタム オブジェクト名が指定されている場合。  もしそうなら、そうします
     // オブジェクトの新しいインスタンスを返します
     if ( ! is_null($object_name))
     {
      $CI =& get_instance();
      if ( ! isset($CI->$object_name))
      {
       return $this->_ci_init_class($class, '', $params, $object_name);
      }
     }
     $is_duplicate = TRUE;
     log_message('debug', $class." クラスはすでにロードされています。2 回目の試行は無視されました。");
     戻ります;
    }
    include_once($filepath);
    $this->_ci_loaded_files[] = $filepath;
    return $this->_ci_init_class($class, '', $params, $object_name);
   }
  } // FOREACH を終了します
  // このクラスにまだ到達していない場合、最後の発言はこのクラス会は同じ名前の子リストの下にありません
  if ($subdir == '')
  {
   $path = strto lower($class).'/'.$class;
   return $this->_ci_load_class($path, $params);
  }
  // 加ダウンロード失败,报错
  if ($is_duplicate == FALSE)
  {
   log_message('error', "要求されたクラスをロードできません: ".$class);
   show_error("要求されたクラスをロードできません: ".$class);
  }
 }
 // ------------------------------------------------ --------------------
 /**
* ロードされたクラスをインスタンス化します
​*/
 保護された関数 _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
 {
  // 有無の設定情報
  if ($config === NULL)
  {
   // パッケージパスを含む設定パスを取得します
   $config_component = $this->_ci_get_component('config');
   if (is_array($config_component->_config_paths))
   {
    // 最初に見つかったファイルで中断し、ファイルをパッケージ化します
    // デフォルトのパスでは上書きされません
    foreach ($config_component->_config_paths as $path)
    {
     // サーバーでは大文字と小文字の両方をテストします
     // ファイル名に関しては大文字と小文字が区別されます。環境を確認してください
     // まずはグローバル
     if (define('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strto lower($class).'.php'))
     {
      include($path .'config/'.ENVIRONMENT.'/'.strto lower($class).'.php');
      休憩;
     }
     elseif (define('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strto lower($class)).'.php'))
     {
      include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strto lower($class)).'.php');
      休憩;
     }
     elseif (file_exists($path .'config/'.strto lower($class).'.php'))
     {
      include($path .'config/'.strto lower($class).'.php');
      休憩;
     }
     elseif (file_exists($path .'config/'.ucfirst(strto lower($class)).'.php'))
     {
      include($path .'config/'.ucfirst(strto lower($class)).'.php');
      休憩;
     }
    }
   }
  }
  if ($prefix == '')
  { //システム下ライブラリ
   if (class_exists('CI_'.$class))
   {
    $name = 'CI_'.$class;
   }
   elseif (class_exists(config_item('subclass_prefix').$class))
   { //扩展ライブラリ
    $name = config_item('subclass_prefix').$class;
   }
   それ以外
   {
    $name = $class;
   }
  }
  それ以外
  {
   $name = $prefix.$class;
  }
  // クラス名は有効ですか?
  if ( ! class_exists($name))
  {
   log_message('error', "存在しないクラス: ".$name);
   show_error("存在しないクラス: ".$class);
  }
  // クラスを割り当てる変数名を設定します
  // カスタム クラス名が指定されましたか?  もしそうなら使わせていただきます
  $class = strto lower($class);
  if (is_null($object_name))
  {
   $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
  }
  それ以外
  {
   $classvar = $object_name;
  }
  // クラス名とオブジェクト名を保存します
  $this->_ci_classes[$class] = $classvar;
  // 初期化の種類の例をCI超级句柄
  $CI =& get_instance();
  if ($config !== NULL)
  {
   $CI->$classvar = 新しい $name($config);
  }
  それ以外
  {
   $CI->$classvar = 新しい $name;
  }
 }
 // ------------------------------------------------ --------------------
 /**
* オートローダー
*
* autoload.php で設定される自動読み込みファイルは次のとおりです:
                                                                    2. 図書館
3. ヘルパーファイル
4. カスタム構成ファイル
| 5. 言語ファイル
6. モデル
| ​*/
 プライベート関数 _ci_autoloader()
 {
  if (define('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
  {
   include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
  }
  それ以外
  {
   include(APPPATH.'config/autoload.php');
  }
  if ( ! isset($autoload))
  {
   FALSE を返します;
  }
  // パッケージの自動追加、つまり package_path をライブラリ、モデル、ヘルパー、config に追加します
  if (isset($autoload['packages']))
  {
   foreach ($autoload['packages'] as $package_path)
   {
$this->add_package_path($package_path);
}
}
//設定ファイルをロード
if (count($autoload['config']) > 0)
{
$CI =& get_instance();
foreach ($autoload['config'] as $key => $val)
{
$CI->config->load($val);
}
}
// ヘルパーと言語をロードします
foreach (array('helper', ' language') as $type)
{
if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
{
$this->$type($autoload[$type]);
}
}
// これは以前のバージョンとの互換性のためのようです
if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
{
$autoload['libraries'] = $autoload['core'];
}
// ライブラリをロードします
if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
{
//データベースをロード
if (in_array('データベース', $autoload['ライブラリ']))
{
$this->database();
$autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
}
// 他のすべてのライブラリをロードします
foreach ($autoload['libraries'] as $item)
{
$this->ライブラリ($item);
}
}
// モデルを自動ロードします
if (isset($autoload['model']))
{
$this->model($autoload['model']);
}
}
//------------------------------------------------ ------------------
/**
* オブジェクトのプロパティで構成される連想配列を返します
​*/
保護された関数 _ci_object_to_array($object)
{
return (is_object($object)) ? get_object_vars($object) : $object;
}
//------------------------------------------------ ------------------
/**
* CI コンポーネントのインスタンスを取得します
​*/
保護された関数 &_ci_get_component($component)
{
$CI =& get_instance();
$CI->$component;
を返します }
//------------------------------------------------ ------------------
/**
* ファイル名を処理するこの関数は主に正しいファイル名を返します
​*/
保護された関数 _ci_prep_filename($filename, $extension)
{
if ( ! is_array($filename))
{
戻り値 array(strto lower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension));
}
それ以外
{
foreach ($filename as $key => $val)
{
$filename[$key] = strto lower(str_replace('.php', '', str_replace($extension, '', $val)).$extension);
}
$filename を返します;
}
}
}

ci フレームワークを使用してデフォルトのテンプレート アドレスを変更するにはどうすればよいですか?

application/core/MY_Load.php
MY_ は application/config/config.php のプレフィックスです $config['subclass_prefix'] = 'MY_'; 設定
class MY_Loader extends CI_Loader{public function __construct(){parent::__construct ();$this->_ci_view_paths = array(FCPATH.'/templates/'=> TRUE);}}//FCPATH は application、system、index.php と同階層のファイルディレクトリです。アプリケーションとシステムと同じレベルに新しいテンプレート ディレクトリを作成します。このディレクトリは、変更されたテンプレート ディレクトリです

PHP CI フレームワークで問題が発生しました

致命的なエラー: クラス 'Test_model' が D:\wamp\www\CodeIgniter_2.1.2\system\core\Loader.php の 303 行目に見つかりません
これは、Test_model クラスが見つからないことを意味します
クラス名が間違っていますもちろん見つかりません
以下はモデルコードで、ファイル名はtest_model.phpです: (クラス名はファイル名と一致している必要があります)

class Test_m extends CI_Model{ // すべて変更するのが最善ですtest_model には大文字
以下 コントローラーコードのファイル名は user.php
$this->load->model('test_model'); ロード時に test_model クラスが見つかりません

これは成功するはずです

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/906120.html技術記事 CI フレームワーク ローダー Loader.php ソース コード分析、ciloader.php 名​​前が示すように、ローダーは CI を使用するときに要素をロードします。 $this-load-library() $this-load-view() $ ..
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!