OpenCart 内容未加载到页面中?

OpenCart content not loading in page?

我是 OpenCart 的初学者,我正在尝试使用 PHP 在服务器中上传文件。我已经完成了以下代码。我的问题是,文件已成功上传到服务器,但如果出现错误,我正在尝试加载 LoadA() 函数,但结果未显示在站点中,而是显示在 console.log 中,我不知道不知道是什么错误。

controller/boxupload/upload.php

public function add()
{

    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) 
    {
        if(success) //files are succesfully uploading
        {
            //doing stuff
        }
        if (it is fail)
        {

            $this->LoadA(); // this is not loading in site. Instead it is showing in console.log
        }
    }
}

public function LoadA()
{
    $data['token'] = $this->session->data['token'];
    $this->document->setTitle("!!!!!!!!!!!!Upload failed!!!!!!!!");
    $data['add'] =  $this->url->link('boxupload/upload/add', 'token=' . $this->session->data['token'], 'SSL');
    $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('boxupload/upload.tpl', $data));
}   

然后是这个的tpl文件

controller/boxupload/upload.tpl

$('#button-upload').on('click', function() {
    $('#progress-bar').css('width', '0%');
    $('#form-upload').remove();

    $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

    $('#form-upload input[name=\'file\']').trigger('click');

    if (typeof timer != 'undefined') {
        clearInterval(timer);
    }
    var WID = 30;
    timer = setInterval(function() {
        if ($('#form-upload input[name=\'file\']').val() != '') {
            clearInterval(timer);

            // Reset everything
            $('.alert').remove();
            $('#progress-bar').css('width', '0%');
            $('#progress-bar').removeClass('progress-bar-danger progress-bar-success');
            $('#progress-text').html('');

            $.ajax({
                url: '<?php echo "index.php?route=boxupload/upload/add&token=$token"; ?>',

                type: 'post',
                //dataType: 'json',
                data: new FormData($('#form-upload')[0]),
                cache: false,
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#button-upload').button('loading');

                    $('#progress-bar').css('width', '50%');

                },
                complete: function() {
                    $('#button-upload').button('reset');
                    $('#progress-bar').css('width', '100%');

                },
                success: function() 
                {   $('#progress-bar').css('width', '80%');


                },

            });
        }

    }, 500);
});

请查看图像中突出显示的区域。

试试这个:

dataType: 'html',

success: function(html) 
{   
    $('#progress-bar').css('width', '80%');
    $('#your-div').html(html);

},

您的 .tpl 文件应该在视图中。

$this->response->setOutput($this->load->view('boxupload/upload.tpl', $data));

加载文件

view/theme/default/template/boxupload/upload.tpl

另外,看看其他一些模板文件。他们通常主要是 HTML。

此外,您还需要重构您的名称,以便它们使用正常的 OpenCart 命名约定。

controller/extension/boxupload/upload.php
view/theme/default/template/extension/boxupload/upload.tpl
etc.