opencart php自定义页面,无需使用“信息"特征 [英] opencart php custom page without using the "information" feature

查看:84
本文介绍了opencart php自定义页面,无需使用“信息"特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create a custom page in opencart.

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

I know I can put a custom page in the information section using the admin area however what I would like is a controller which points to a few other pages.

我不完全了解该怎么做.

I dont fully understand how to do this.

在codeigniter中,您将创建一个控制器和一个视图,并且如果需要,可以在路由文件中设置一些规则,但是我看不到任何类似的东西.

In codeigniter you would create a controller and a view and if needed setup some rules in the routes file but I cannot see anything like this.

请介意为我解释或指出一些有关如何执行此操作的说明.

Would somebody mind explaining or pointing me to some instructions on how to do this please.

谢谢

推荐答案

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

It's pretty simple to do to be honest. You need to create a controller for your file, naming based on the folder and filename. For instance common/home.php has

Class ControllerCommonHome extends Controller

使用index.php?route=common/home访问此对象,并访问index()方法.如果要调用其他方法,例如foo,则需要将方法定义为

This is accessed using index.php?route=common/home and accesses the index() method. If you want to call another method, for instance foo, you would need to define the method as

public function foo() {
    // Code here
}

并使用index.php?route = common/home/foo

and would call it using index.php?route=common/home/foo

对于渲染视图,这有点棘手.基本上,您需要将所有这些添加到控制器方法的末尾

As for rendering the view, that's a bit trickier. Basically you need to add all of this to the end of your controller method

    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主题文件夹中的相同路径

Which will render /catalog/view/theme/your-theme-name/template/common/new_template_file.tpl If that file doesn't exist, it will attempt to use the same path in the default theme folder

我建议您看一些控制器和模板,以掌握所有正确来源,但这是其工作原理的基本要旨

I'd recommend you take a look at a few controllers and templates to get your head around where everything comes from properly, but that's the basic gist of how it works

这篇关于opencart php自定义页面,无需使用“信息"特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆