opencart loader를 살펴본 후 어떻게 작동하는지 이해하려고합니다. 로드의 opencart 로더/호출 파일opencart loader 이해하기
<?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 ($ 파일)).
이 부분은 $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)
을 수행 할까? new Model_ModelA ($ this-> registry)?
새 Model_ModelA ($ this-> registry)의 $ this-> 레지스트리 란 무엇입니까?
좋아, 하루 종일 보내고 몇 가지 기사를 거쳐 내가 찾은 어떤이가하는 일은$this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
실제로 레지스트리 시스템
$registry->set(model_ModelA, new model_ModelA($this->registry))
매우 등에서 같은 모델을 등록되는 몇 가지 테스트를 통해 확인