php - 管理员自定义页面 opencart 中的权限被拒绝

标签 php opencart opencart2.x opencart-module

我遵循了以下程序,但我仍然遇到权限被拒绝的错误。 我正在使用 opencart 2.x

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

您的文件名和 Controller 名称在 desc 顺序上应该相同:

helloworld.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) 在admin/view/template/custom/hello.tpl新建一个文件

Hello.tpl



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

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) 然后您需要启用插件以避免权限被拒绝的错误:

Opencart > 管理员 > 用户 > 用户组 > 管理员 > 编辑 选择并启用访问权限。

最佳答案

这里是在admin中添加自定义helloworld模块的方法

  1. 创建 admin/controller/custom/helloworld.php

    <?php
    class ControllerCustomHelloworld extends Controller {
    
     public function index() {
    
     $this->load->language('custom/helloworld');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->load->model('custom/helloworld');        
    
     $data['header'] = $this->load->controller('common/header');
     $data['column_left'] = $this->load->controller('common/column_left');
     $data['footer'] = $this->load->controller('common/footer');
     $this->response->setOutput($this->load->view('custom/helloworld.tpl', $data));
    
     }
    }
    ?>
    
  2. 创建admin/model/custom/helloworld.php

    <?php
    class ModelCustomHelloworld extends Model {
    
    public function helloworldmodel(){
    
     }
    }
    ?>
    
  3. 创建admin/language/english/custom/helloworld.php

    <?php
    // Heading
    $_['heading_title']          = 'Hello world Admin module';
    
    ?>
    
  4. 创建admin/view/template/custom/helloworld.tpl

    <?php echo $header; ?><?php echo $column_left; ?>
    <h1><?php echo "This is helloworld admin module in opencart 2.x.x.x "; ?></h1>         
    <?php echo $footer; ?>
    
  5. 转到 系统 -> 用户 -> 用户组 -> 编辑管理员组。选择全部访问权限修改权限并保存。 enter image description here

这是教程http://blog.a2bizz.com/index.php/2015/12/17/create-custom-module-in-opencart-admin/

关于php - 管理员自定义页面 opencart 中的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326952/

相关文章:

json - Opencart管理页面301永久移动

php - 第 17 行警告 : failed to open stream: Invalid argument in C:\xampp\htdocs\WWW\index. php

php - 在 PHP 中使用 URL 的最后一部分作为查询字符串,而不是目录路径

javascript - 如何将 slider 轮播的最小高度设置为等于图像的不同高度?

css - Opencart 主题 - 使用 CSS 更改表格标题的颜色?

php - 在 opencart html 模块中使用 php 标签

php - Opencart从唯一表进行sql查询

html - Opencart Checkout 问题 2.0.2.0

php - 使用 Phpexcel 复制包含数据透视表和图表的工作表

php - 在 PHP 中计算每周的事件数