0

当我尝试在我的模块上保存更改时,它说权限被拒绝。我很确定它来自控制器文件。我已启用用户组的所有权限:“管理员”。但我真的不知道它来自哪里,因为这是我的第一个 Opencart 3 模块。我相信它与帖子部分有关,因为它仅在保存后才会出现。

控制器文件中的代码:

<?php
class Controllerextensionmodulecartreminder extends Controller {
    private $error = array(); // This is used to set the errors, if any.

    public function index() {
        // Loading the language file of cart reminder
        $this->load->language('extension/module/cartreminder'); 

        // Set the title of the page to the heading title in the Language file i.e., Cart Reminder
        $this->document->setTitle($this->language->get('heading_title'));

        // Load the Setting Model  (All of the OpenCart Module & General Settings are saved using this Model )
        $this->load->model('setting/setting');

        // Start If: Validates and check if data is coming by save (POST) method
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            // Parse all the coming data to Setting Model to save it in database.
            $this->model_setting_setting->editSetting('cartreminder', $this->request->post);

            // To display the success text on data save
            $this->session->data['success'] = $this->language->get('text_success');

            // Redirect to the Module Listing
            $this->response->redirect($this->url->link('extension/module', 'user_token=' . $this->session->data['user_token'], 'SSL'));
        }

        // Assign the language data for parsing it to view
        $data['heading_title'] = $this->language->get('heading_title');

        $data['text_edit']    = $this->language->get('text_edit');
        $data['text_enabled'] = $this->language->get('text_enabled');
        $data['text_disabled'] = $this->language->get('text_disabled');
        $data['text_content_top'] = $this->language->get('text_content_top');
        $data['text_content_bottom'] = $this->language->get('text_content_bottom');      
        $data['text_column_left'] = $this->language->get('text_column_left');
        $data['text_column_right'] = $this->language->get('text_column_right');

        $data['entry_code'] = $this->language->get('entry_code');
        $data['entry_layout'] = $this->language->get('entry_layout');
        $data['entry_position'] = $this->language->get('entry_position');
        $data['entry_status'] = $this->language->get('entry_status');
        $data['entry_sort_order'] = $this->language->get('entry_sort_order');

        $data['button_save'] = $this->language->get('button_save');
        $data['button_cancel'] = $this->language->get('button_cancel');
        $data['button_add_module'] = $this->language->get('button_add_module');
        $data['button_remove'] = $this->language->get('button_remove');

        // This Block returns the warning if any
        if (isset($this->error['warning'])) {
            $data['error_warning'] = $this->error['warning'];
        } else {
            $data['error_warning'] = '';
        }

        // This Block returns the error code if any
        if (isset($this->error['code'])) {
            $data['error_code'] = $this->error['code'];
        } else {
            $data['error_code'] = '';
        }     

        // 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/home', 'user_token=' . $this->session->data['user_token'], 'SSL'),
            'separator' => false
        );
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_module'),
            'href'      => $this->url->link('extension/module', 'user_token=' . $this->session->data['user_token'], 'SSL'),
            'separator' => ' :: '
        );
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('extension/module/cartreminder', 'user_token=' . $this->session->data['user_token'], 'SSL'),
            'separator' => ' :: '
        );

        $data['action'] = $this->url->link('extension/module/cartreminder', 'user_token=' . $this->session->data['user_token'], 'SSL'); // URL to be directed when the save button is pressed

        $data['cancel'] = $this->url->link('extension/module', 'user_token=' . $this->session->data['user_token'], 'SSL'); // 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['cartreminder_text_field'])) {
            $data['cartreminder_text_field'] = $this->request->post['cartreminder_text_field'];
        } else {
            $data['cartreminder_text_field'] = $this->config->get('cartreminder_text_field');
        }   

        // This block parses the status (enabled / disabled)
        if (isset($this->request->post['cartreminder_status'])) {
            $data['cartreminder_status'] = $this->request->post['cartreminder_status'];
        } else {
            $data['cartreminder_status'] = $this->config->get('cartreminder_status');
        }

        $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('extension/module/cartreminder', $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/cartreminder')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        // Block to check if the cartreminder_text_field is properly set to save into database,
        // otherwise the error is returned
        if (!$this->request->post['cartreminder_text_field']) {
            $this->error['code'] = $this->language->get('error_code');
        }
        /* End Block*/

        // Block returns true if no error is found, else false if any error detected
        if (!$this->error) {
            return true;
        } else {
            return false;
        }
    }
}
4

1 回答 1

0

没关系,我找到了。我不得不从

$this->response->redirect($this->url->link('extension/module', 'user_token=' . $this->session->data['user_token'], 'SSL'));

$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
于 2017-08-10T00:11:58.200 回答