【问题标题】:Prestashop 1.7 - show custom success message on file uploadPrestashop 1.7 - 在文件上传时显示自定义成功消息
【发布时间】:2021-06-28 00:30:47
【问题描述】:

我正在 Prestashop 上开发我的第一个模块,该模块包括从 xlsx 文件创建产品。

我能够在上传方法上显示自定义错误消息,但无法显示成功消息。

波纹管代码有效,我收到一条自定义错误消息:

 if (file_exists($this->uploadDirectory.DIRECTORY_SEPARATOR.$_FILES["file"]['name'])) {
            $this->context->smarty->assign('error', 'O ficheiro já existe!');
            $this->uploadError = true;
            return false;
   }

下面的代码有效,但我没有收到任何成功消息:

if (!$this->uploadError) {
            if (move_uploaded_file($_FILES["file"]["tmp_name"], $this->uploadDirectory. $_FILES["file"]["name"])) {
                $this->context->smarty->assign('success', "O ficheiro " . $file['name'] . " foi gravado com sucesso.");
                return true;
            }
        }

getContent函数代码:

/**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitExpodirectModule')) == true) {
            $this->postProcess();
        }

        $this->context->smarty->assign('module_dir', $this->_path);

        $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

        $outputEnd= $this->context->smarty->fetch($this->local_path.'views/templates/admin/table.tpl');


        return $output.$this->renderForm().$outputEnd;
    }

【问题讨论】:

  • 展示你的 getContent() 方法并告诉我们这两段代码是如何被调用的。
  • 我已经发布了我的 getContent() 函数,但也许最好发布整个课程?你对此有何看法?
  • @Arun Vishwakarama 的回答应该可以正常工作。您的 getContent 方法属于扩展 Module 类的类,对吗?
  • 是的,我通过 prestashop 模块生成器生成了模块,并且类扩展了模块

标签: php prestashop-1.7 prestashop-modules


【解决方案1】:

上传成功后在 getContent 中使用它并在输出中添加它

$success_message = $this->displayConfirmation($this->l('要在此处显示的消息。'));

返回 $success_message.form 内容和其他输出

【讨论】:

  • 您好阿伦,感谢您的回答。我以前试过。它不起作用:(
  • 你能展示一些代码以及你在哪个函数中编写的吗?
  • 你好 Arunl,我已经编辑了我的帖子并添加了 getContent() 函数代码
  • 好的,你正在模块页面使用
猜你喜欢
  • 2019-02-07
  • 2016-11-28
  • 1970-01-01
  • 1970-01-01
  • 2019-09-21
  • 1970-01-01
  • 2013-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多