搜索
开启辅助访问 切换到宽版

QQ登录

只需一步,快速开始

扫一扫,访问微社区

注册 找回密码
查看: 1760|回复: 2
打印 上一主题 下一主题

小白开发插件遇到问题

[复制链接]
跳转到指定楼层
楼主
发表于 2019-3-7 14:26:58 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
第一次开发插件,找了一个例子https://code.tutsplus.com/tutori ... --cms-21873opencard
发现有点不一样,现在换了twig模板,于是按照里面原有的代码改了一下,发现还是不行,在“插件管理” ,写的插件能看见,也能“安装”,但是点“编辑”的话出现:

controller/extension/modual/helloword.php:

<?php
class ControllerModuleHelloworld extends Controller {
    private $error = array(); // This is used to set the errors, if any.
   
    public function install(){
        $sql = "ALTER TABLE " . DB_PREFIX . "customer ADD `gender` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT 'm'";
        $this->db->query($sql);
    }
    public function uninstall(){
        $sql = "ALTER TABLE `" . DB_PREFIX . "customer` DROP `gender`";
        $this->db->query($sql);
    }
   
   
    public function index() {   // Default function
        $this->language->load('extension/module/helloworld'); // Loading the language file of helloworld
        
        $this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
        
        $this->load->model('setting/setting'); // Load the Setting Model  (All of the OpenCart Module & General Settings are saved using this Model )
        $this->load->model('design/layout');
        
        
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { // Start If: Validates and check if data is coming by save (POST) method
            $this->model_setting_setting->editSetting('modual_helloworld', $this->request->post);      // Parse all the coming data to Setting Model to save it in database.
            
            $this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save
            $this->response->redirect($this->url->link('marketplace/extension' . '&type=module', 'user_token=' . $this->session->data['user_token'], true));
//             $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
        } // End If
        
        /*Assign the language data for parsing it to view*/

        $data['header'] = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer'] = $this->load->controller('common/footer');
        
        /*This Block returns the warning if any*/
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }
        /*End Block*/
        

        
        
        /* Making of Breadcrumbs to be displayed on site*/
        $data['breadcrumbs'] = array();
        
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['token'], true)
        );
        
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_module'),
            'href'      => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['token'] . '&type=module', true)
        );
        
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('extension/module/helloworld', 'user_token=' . $this->session->data['user_token'], true)
        );
        
        /* End Breadcrumb Block*/
        
        $data['action'] = $this->url->link('extension/module/helloworld', 'user_token=' . $this->session->data['user_token'], true); // URL to be directed when the save button is pressed
        
        $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true); // URL to be redirected when cancel button is pressed
        
        
        /* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
        
        if (isset($this->request->post['module_helloworld_status'])) {
            $data['module_helloworld_status'] = $this->request->post['module_helloworld_status'];
        } else {
            $data['module_helloworld_status'] = $this->config->get('module_helloworld_status');
        }
        /* End Block*/
        
        $this->data['modules'] = array();
        
        /* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
        if (isset($this->request->post['helloworld_module'])) {
            $data['modules'] = $this->request->post['helloworld_module'];
        } elseif ($this->config->get('helloworld_module')) {
            $data['modules'] = $this->config->get('helloworld_module');
        }
        /* End Block*/
        
        $this->load->model('design/layout'); // Loading the Design Layout Models
        
        $this->data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
        
        $this->template = 'module/helloworld.tpl'; // Loading the helloworld.tpl template
        $this->children = array(
            'common/header',
            'common/footer'
        );  // Adding children to our default template i.e., helloworld.tpl
        

        $this->response->setOutput($this->load->view('extension/module/helloworld', $data));
    }
   
   
    /* Function that validates the data when Save Button is pressed */
    protected function validate() {
        
        /* Block to check the user permission to manipulate the module*/
        if (!$this->user->hasPermission('modify', 'extension/module/helloworld')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }
        /* End Block*/

        return !$this->error;
        /* End Block*/
    }
    /* End Validation Function*/
}


language/en-gb/extension/helloworld.php:

<?php
// English file
$_['heading_title']                          = "Karley Salutation";
$_['text_enabled']                           = "Enabled";
$_['text_disabled']                                 = "Disabled";
$_['button_save']                            = "Save";
$_['button_cancel']                          = "Cancel";
$_['entry_status']                   = "Status";
$_['text_edit']                                         = "Karley Salutation Module";
$_['text_home']                                   = "Dashboard";
$_['text_module']                                   = "Modules";
$_['text_success']                                      = 'Changes were successfully changed.';
?>

view/template/extension/modual/helloworld.twig

{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-right">
        <button type="submit" form="form-module" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fas fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-light"><i class="fas fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
      <div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> {{ error_warning }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    <div class="card">
      <div class="card-header"><i class="fas fa-pencil-alt"></i> {{ text_edit }}</div>
      <div class="card-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module">
          <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-10">
              <select name="module_helloworld_status" id="input-status" class="form-control">
                {% if module_helloworld_status %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  <option value="0">{{ text_disabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{{ footer }}


求大神指导~~
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享分享 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2019-3-7 14:29:05 | 只看该作者
自己增加点人气~
回复 支持 反对

使用道具 举报

板凳
 楼主| 发表于 2019-3-8 15:03:05 | 只看该作者
求大神啊!!!谢谢了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

QQ|手机版|OpenCart - 中文官方网站 ( 蜀ICP备09033774号|人工智能

GMT+8, 2024-4-20 08:19 , Processed in 0.062747 second(s), 22 queries , Gzip On.

快速回复 返回顶部 返回列表