2017-01-15 5 views
0

opencartローダーを調べ、それがどのように機能するかを理解しようとしています。ロード用opencartローダー/呼び出しファイルopencartローダーを理解する

<?php 
final class Loader { 
    private $registry; 

    public function __construct($registry) { 
     $this->registry = $registry; 
    } 

    public function controller($route, $args = array()) { 
     $action = new Action($route, $args); 

     return $action->execute($this->registry); 
    } 

    public function model($model) { 
     $file = DIR_APPLICATION . 'model/' . $model . '.php'; 
     $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); 

     if (file_exists($file)) { 
      include_once($file); 

      $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); 
     } else { 
      trigger_error('Error: Could not load model ' . $file . '!'); 
      exit(); 
     } 
    } 

    public function view($template, $data = array()) { 
     $file = DIR_TEMPLATE . $template; 

     if (file_exists($file)) { 
      extract($data); 

      ob_start(); 

      require($file); 

      $output = ob_get_contents(); 

      ob_end_clean(); 

      return $output; 
     } else { 
      trigger_error('Error: Could not load template ' . $file . '!'); 
      exit(); 
     } 
    } 

    public function library($library) { 
     $file = DIR_SYSTEM . 'library/' . $library . '.php'; 

     if (file_exists($file)) { 
      include_once($file); 
     } else { 
      trigger_error('Error: Could not load library ' . $file . '!'); 
      exit(); 
     } 
    } 

    public function helper($helper) { 
     $file = DIR_SYSTEM . 'helper/' . $helper . '.php'; 

     if (file_exists($file)) { 
      include_once($file); 
     } else { 
      trigger_error('Error: Could not load helper ' . $file . '!'); 
      exit(); 
     } 
    } 

    public function config($config) { 
     $this->registry->get('config')->load($config); 
    } 

    public function language($language) { 
     return $this->registry->get('language')->load($language); 
    } 
} 

これはこれは私が上記のコードから作るものである私は

public function model($model) { 
$file = DIR_APPLICATION . 'model/' . $model . '.php'; 
$class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); 

if (file_exists($file)) { 
    include_once($file); 

    $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); 
} else { 
    trigger_error('Error: Could not load model ' . $file . '!'); 
    exit(); 
} 
} 

で探しています一部です。モデルが呼び出されると(ModelAをModelAとする)、$ファイルはcatalog/model/ModelA.phpに設定され、$クラスはModelModelAに設定され、ファイル($ file)が存在するかどうか、それ(include_once($ file))。

この部分は私が分かりません$this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));、これはモデルファイル名を登録しようとしていますが、どうしたのですか?

OCのindex.phpが表示されている場合は、$registry->set('db', $db)のようにレジストリがいくつか作成されています。しかし、このローダーレジストリは私に混乱しています。私は最初の部分を 'ModelA'を 'Model_ModelA'に変換する'model_' . str_replace('/', '_', $model)を取得しますが、これは何ですか?new $class($this->registry)は何ですか...新しいModel_ModelA($ this-> registry)?

新しいModel_ModelA($ this-> registry)の$ this-> registryとは何ですか?一日過ごし、私は何これは$this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));が実際にあるんが、かなりのようなレジストリシステム

$registry->set(model_ModelA, new model_ModelA($this->registry)) 

でそのようにモデルを登録することをいくつかのテストを経て発見され、確認され、いくつかの記事を経た後

答えて

1

さて、他のものはindex.phpに登録されています。

関連する問題