`

opencart核心代码方法

阅读更多

opencart核心代码方法

public function __construct($route, $args = array()) {
$path = ”;
$parts = exe(‘../’, ”, (string)$route));
foreach ($parts as $part) { plode(‘/’, str_replac
$path .= $part;
if (is_dir(DIR_APPLICATION . ‘controller/’ . $path)) {
$path .= ‘/’;

array_shift($parts);

continue;
}

if (is_file(DIR_APPLICATION . ‘controller/’ . str_replace(array(‘../’, ‘..\\’, ‘..’), ”, $path) . ‘.php’)) {
$this->file = DIR_APPLICATION . ‘controller/’ . str_replace(array(‘../’, ‘..\\’, ‘..’), ”, $path) . ‘.php’;

$this->class = ‘Controller’ . preg_replace(‘/[^a-zA-Z0-9]/’, ”, $path);

array_shift($parts);

break;
}
}

if ($args) {
$this->args = $args;
}

$method = array_shift($parts);

if ($method) {
$this->method = $method;
} else {
$this->method = ‘index’;
}
}

private function execute($action) {
if (file_exists($action->getFile())) {
require_once($action->getFile());

$class = $action->getClass();

$controller = new $class($this->registry);

if (is_callable(array($controller, $action->getMethod()))) {

分析调用那个controler
$action = call_user_func_array(array($controller, $action->getMethod()), $action->getArgs());
} else {
$action = $this->error;

$this->error = ”;
}
} else {
$action = $this->error;

$this->error = ”;
}

return $action;
}
}
public function dispatch($action, $error) {
$this->error = $error;

foreach ($this->pre_action as $pre_action) {
$result = $this->execute($pre_action);

if ($result) {
$action = $result;

break;
}
}

while ($action) {
$action = $this->execute($action);
}
}
protected function getChild($child, $args = array()) {

$action = new Action($child, $args);
if (file_exists($action->getFile())) {
require_once($action->getFile());
$class = $action->getClass();
$controller = new $class($this->registry);
分析调用那个controler
$controller->{$action->getMethod()}($action->getArgs());
return $controller->output;
} else {
trigger_error(‘Error: Could not load controller ‘ . $child . ‘!’);
exit();
}
}
protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error(‘Error: Could not load template ‘ . DIR_TEMPLATE . $this->template . ‘!’);
exit();
}
}

opencart教程

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics