说实话,这很简单。您需要为您的文件创建一个控制器,根据文件夹和文件名命名。例如common/home.php
has
Class ControllerCommonHome extends Controller
这是使用以下方式访问的index.php?route=common/home
并访问index()
方法。如果你想调用另一个方法,例如 foo,你需要将该方法定义为
public function foo() {
// Code here
}
并使用index.php?route=common/home/foo 来调用它
至于渲染视图,这有点棘手。基本上你需要将所有这些添加到控制器方法的末尾
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/new_template_file.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/new_template_file.tpl';
} else {
$this->template = 'default/template/common/new_template_file.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
哪个会渲染/catalog/view/theme/your-theme-name/template/common/new_template_file.tpl
如果该文件不存在,它将尝试使用相同的路径default
主题文件夹
我建议您查看一些控制器和模板,以了解所有内容的正确来源,但这就是其工作原理的基本要点