2015-09-01 58 views
1

我遵循以下程序但仍然我得到权限拒绝错误。 我使用Opencart的2.x的权限被拒绝在管理员自定义页面opencart

1)创建管理/控制/自定义一个新的文件/ helloworld.php

你的文件名和控制器的名称应该是倒序相同:

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 /视图/模板/自定义一个新的文件/ 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 /模型/自定义一个新的文件/ 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的>管理员>用户>用户组>管理员>编辑 选择并启用访问权限。

回答

3

这里就是这样,添加自定义的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. 转到system -> users -> user groups -> edit Administrator group。全选至access permissionmodify permission并保存。 enter image description here

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

+1

真的很有用。作品 –