opencart php自定义页面,不使用"信息"功能

jag*_*get 10 php opencart

我想在opencart中创建一个自定义页面.

我知道我可以使用管理区域在信息部分放置一个自定义页面,但我想要的是指向其他几个页面的控制器.

我不完全明白如何做到这一点.

在codeigniter中你可以创建一个控制器和一个视图,如果需要在routes文件中设置一些规则,但我看不到这样的东西.

有人会介意解释或指出我如何做到这一点的一些指示.

谢谢

Jay*_*ord 17

说实话,这很简单.您需要为文件创建一个控制器,根据文件夹和文件名命名.例如common/home.php

Class ControllerCommonHome extends Controller
Run Code Online (Sandbox Code Playgroud)

使用index.php?route=common/home和访问该index()方法可以访问它.如果要调用另一个方法,例如foo,则需要将方法定义为

public function foo() {
    // Code here
}
Run Code Online (Sandbox Code Playgroud)

并使用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());
Run Code Online (Sandbox Code Playgroud)

将呈现/catalog/view/theme/your-theme-name/template/common/new_template_file.tpl 如果该文件不存在,它将尝试在default主题文件夹中使用相同的路径

我建议你看一下几个控制器和模板,让你了解一切来自哪里,但这是它的工作原理的基本要点