找不到Opencart自定义控制器功能

时间:2019-03-06 13:04:01

标签: php opencart

当我尝试从jquery发送POST请求时,我被带走-找不到404

有我的自定义控制器:

<?php
class ControllerCardsCards extends Controller {
    public function index() {
        $this->document->setTitle($this->config->get('config_meta_title'));
        $this->document->setDescription($this->config->get('config_meta_description'));
        $this->document->setKeywords($this->config->get('config_meta_keyword'));

        if (isset($this->request->get['route'])) {
            $this->document->addLink($this->config->get('config_url'), 'canonical');
        }

        $data['column_left'] = $this->load->controller('common/column_left');
        $data['column_right'] = $this->load->controller('common/column_right');
        $data['content_top'] = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer'] = $this->load->controller('common/footer');
        $data['header'] = $this->load->controller('common/header');

        $this->response->setOutput($this->load->view('cards/registraion', $data));
        $this->load->model('cards/cards');
        $this->log->write('Controller main');

    }

    public function addcardquery($data){
        $this->log->write('fired addCardQuery function');
        $this->load->Model('cards/cards');
        $this->load->language('cards/cards');
        $temp = $this->model_cards_cards->insertCard($data);
    }

还有我的jquery函数:

$(document).ready(function(){ 
    $("#regCardSubmit").click(function(event) { 
          event.preventDefault();
                var myObject = new Object();
                myObject.lastname = $('#card_reg_lastname').val();

                myObject.firstname = $('#card_reg_firstname').val();
                myObject.middlename = $('#card_reg_middlename').val();
                myObject.cardnum = $('#card_reg_card_num').val();
                myObject.birthday = $('#card_reg_birthday').val();
                myObject.phone = $('#card_reg_phone_num').val();
                myObject.email = $('#card_reg_email').val();

                var data = {"action": "addcardquery"};
                data = $(this).serialize() + "&" + $.param(data);
                var outjson = JSON.stringify(myObject);
                //alert(outjson);
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: "index.php?route=cards/cards/addcardquery",
                    data: outjson,
                    success: function(data) { alert(outjson); },
                    error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
                });
                return false;
    });
});

addcardquery函数始终不会触发,我曾尝试从浏览器中调用路径index.php?route = cards / cards / addcardquery,但我却得到了相同的结果。

3 个答案:

答案 0 :(得分:1)

您可以替换的第一个秋天

$this->load->Model('cards/cards'); 

收件人

$this->load->model('cards/cards');

第二次更改在这里

$temp = $this->model_cards_cards->insertCard($data);

添加以下代码后

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

我很好。

答案 1 :(得分:0)

检查您的OCMOD修改。看来您一切都正确,但是框架并未对其进行查看。

转到system/storage/modification/catalog/controller/cards/cards.php并检查是否存在(您的存储文件夹可以移到上方,因此也要检查)

答案 2 :(得分:0)

我注意到您做错了几件事,但不会导致此问题。

  • $data不应放在函数参数中-OpenCart不能那样工作
  • $this->load->Model应该为$this->load->model(请注意小写的m

如某人所建议的那样,VQMod / OCMod不太可能是罪魁祸首,因为他们将需要使用自己的系统来主动编辑文件。我能想到的一种可能的解释是,您在php中启用了类似opcache的功能,并且在开发代码时需要禁用此功能