【问题标题】:opencart php custom page without using the "information" featureopencart php自定义页面不使用“信息”功能
【发布时间】:2012-02-28 22:23:16
【问题描述】:

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

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

我不完全理解如何做到这一点。

在 codeigniter 中,您将创建一个控制器和一个视图,如果需要在路由文件中设置一些规则,但我看不到这样的任何东西。

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

谢谢

【问题讨论】:

    标签: php opencart


    【解决方案1】:

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

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

    我建议您查看一些控制器和模板,以了解所有内容的正确来源,但这是其工作原理的基本要点

    【讨论】:

    • 这里可能缺少一些东西,但不确定是什么。标准文件确实有这种结构,但也许有一个地方需要注册新的扩展或任何东西?
    • 如果您正在创建全新的页面,那么不,它们不需要注册。如果是模块,基本原理是一样的,但是模块需要在后台安装,并设置为启用位置等
    【解决方案2】:

    请关注此页面,希望更多使用完整。

    http://code.tutsplus.com/tutorials/create-a-custom-page-in-opencart--cms-22054

    OpenCart 是使用流行的编程 MVC 模式构建的。该模式还添加了一个名为“L”的元素——一种语言部分——因此在 OpenCart 中它被称为 MVC-L 模式。我不会详细介绍 MVC 模式,因为它是一种非常流行和熟悉的设计模式,我们已经在其他教程中详细介绍了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      相关资源
      最近更新 更多