php 如何在 opencart 中创建自定义管理页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10700761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:51:32  来源:igfitidea点击:

How to create a custom admin page in opencart?

phpe-commerceopencart

提问by TheBlackBenzKid

I want to know how to make a custom admin panel page in opencart.

我想知道如何在 opencart 中制作自定义管理面板页面。

Requires login with the controller - the admin panel does not seem to use the same controller as the normal site. I know how to make custom pages with opencart(but this is not for the admin)

需要使用控制器登录 - 管理面板似乎没有使用与普通站点相同的控制器。我知道如何使用 opencart 制作自定义页面(但这不适用于管理员)

A simple Hello World example would be great

一个简单的 Hello World 示例会很棒

回答by TheBlackBenzKid

OpenCart 2.x

OpenCart 2.x

The path names have changed in OpenCart 2 - you will want to create

OpenCart 2 中的路径名称已更改 - 您需要创建

admin/controller/extension/module/hello.php admin/language/en-gb/extension/module/hello.php admin/view/template/extension/module/hello.tpl Then the route becomes

admin/controller/extension/module/hello.php admin/language/en-gb/extension/module/hello.php admin/view/template/extension/module/hello.tpl 然后路由就变成了

admin/index.php?route=extension/module/hello

admin/index.php?route=extension/module/hello

OpenCart 1.x

OpenCart 1.x

  • Include full MVC flow.
  • 包括完整的 MVC 流程。

I found out how to do this. OpenCart uses the MVC pattern. I recommend reading about How to be an OpenCart Guru?post about learning how the system works - this Admin workflow should also suffice for customer end.

我发现了如何做到这一点。OpenCart 使用 MVC 模式。我建议阅读如何成为 OpenCart 大师?发布关于了解系统如何工作的帖子 - 此管理工作流程也应该足以满足客户的需求。

1) Create a new file in admin/controller/custom/helloworld.php

1)新建一个文件 admin/controller/custom/helloworld.php

Your filename and controller name should be the same in desc order:

您的文件名和控制器名称应按降序排列:

helloworld.php

你好世界.php

<?

class ControllerCustomHelloWorld extends Controller{ 
    public function index(){
                // VARS
                $template="custom/hello.tpl"; // .tpl location and file
        $this->load->model('custom/hello');
        $this->template = ''.$template.'';
        $this->children = array(
            'common/header',
            'common/footer'
        );      
        $this->response->setOutput($this->render());
    }
}
?>

2) Create a new file in admin/view/template/custom/hello.tpl

2)新建一个文件 admin/view/template/custom/hello.tpl

Hello.tpl

你好.tpl

<?php echo $header; ?>
<div id="content">
<h1>HelloWorld</h1>
<?php
echo 'I can also run PHP too!'; 
?>
</div> 
<?php echo $footer; ?>

3) Create a new file in admin/model/custom/hello.php

3)新建一个文件 admin/model/custom/hello.php

<?php
class ModelCustomHello extends Model {
    public function HellWorld() {
        $sql = "SELECT x FROM `" . DB_PREFIX . "y`)"; 
        $implode = array();
        $query = $this->db->query($sql);
        return $query->row['total'];    
    }       
}
?>

4) You then need to enable the plugin to avoid permission denied errors:

4) 然后您需要启用插件以避免权限被拒绝错误:

Opencart > Admin > Users > User Groups > Admin > Edit

Select and Enable the Access Permission.

选择并启用访问权限。

To visit your page go to

要访问您的页面,请访问

www.yoursite.com/opencart/admin/index.php?route=custom/helloworld

www.yoursite.com/opencart/admin/index.php?route=custom/helloworld