简体   繁体   English

Opencart module_id 未附加在管理链接中

[英]Opencart module_id not appending in admin link

I am developing a Opencart module (Version 4.0.0.0).我正在开发一个 Opencart 模块(版本 4.0.0.0)。

Created the module with height and status.创建了具有高度和状态的模块。 Installed the same in the Opencart application.在 Opencart 应用程序中安装相同。 But the problem is when I tried to save the value to the db, it is creating a new row inside "oc_module" table.但问题是当我试图将值保存到数据库时,它在"oc_module"表中创建了一个新行。 While checking I just found that "module_id" is not appending the URL from the module listing page's edit button.在检查时我发现"module_id"没有附加来自模块列表页面编辑按钮的 URL。

The testimonial module link looks like推荐模块链接看起来像

http://localhost/op4/admin/index.php?route=extension/testimonials/module/testimonials&user_token=2e7a4d8fad2e1c4339e9c01bc83d707a http://localhost/op4/admin/index.php?route=extension/testimonials/module/testimonials&user_token=2e7a4d8fad2e1c4339e9c01bc83d707a

extensions --> testimonial --> admin --> controller --> module --> testimonials.php扩展 --> testimonial --> admin --> controller --> module --> testimonials.php

<?php
namespace Opencart\Admin\Controller\Extension\Testimonials\Module;
class Testimonials extends \Opencart\System\Engine\Controller {
    public function index(): void {
        $this->load->language('extension/testimonials/module/testimonials');

        $this->document->setTitle($this->language->get('heading_title'));
        $this->load->model('setting/setting');
        $data['breadcrumbs'] = [];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
        ];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('text_extension'),
            'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
        ];

        if (!isset($this->request->get['module_id'])) {
            $data['breadcrumbs'][] = [
                'text' => $this->language->get('heading_title'),
                'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'])
            ];
        } else {
            $data['breadcrumbs'][] = [
                'text' => $this->language->get('heading_title'),
                'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
            ];
        }

        if (!isset($this->request->get['module_id'])) {
            $data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token']);
        } else {
            $data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
        }

        $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');

        if (isset($this->request->get['module_id'])) {
                $this->load->model('setting/module');

            $module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
            print_r($module_info);
        }

        
        if (isset($module_info['name'])) {
            $data['name'] = $module_info['name'];
        } else {
            $data['name'] = '';
        }


        if (isset($module_info['height'])) {
            $data['height'] = $module_info['height'];
        } else {
            $data['height'] = 200;
        }

        if (isset($module_info['status'])) {
            $data['status'] = $module_info['status'];
        } else {
            $data['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/testimonials/module/testimonials', $data));
    }

    public function save(): void {
        $this->load->language('extension/testimonials/module/testimonials');

        $json = [];

        if (!$this->user->hasPermission('modify', 'extension/testimonials/module/testimonials')) {
            $json['error']['warning'] = $this->language->get('error_permission');
        }

        
        if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
            $json['error']['name'] = $this->language->get('error_name');
        }
        if (!$this->request->post['height']) {
            $json['error']['height'] = $this->language->get('error_height');
        }

        if (!$json) {
            $this->load->model('setting/module');
            if (!isset($this->request->get['module_id'])) {
                $this->model_setting_module->addModule('module_testimonials', $this->request->post);
            } else {
                $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post);
            }

            

            $json['success'] = $this->language->get('text_success');
        }
    

        $this->response->addHeader('Content-Type: application/json');
        $this->response->setOutput(json_encode($json));
    }
}

You have error in your save function.您的保存功能有误。 You need to change: $this->model_setting_module->addModule('module_testimonials', $this->request->post);您需要更改:$this->model_setting_module->addModule('module_testimonials', $this->request->post); to: $this->model_setting_module->addModule('testimonials.testimonials', $this->request->post);至:$this->model_setting_module->addModule('testimonials.testimonials', $this->request->post);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM