php - Prestashop 1.7 - 在文件上传时显示自定义成功消息
问题描述
我正在 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;
}
}
获取内容功能代码:
/**
* 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 中使用它并将其添加到输出中
$success_message = $this->displayConfirmation($this->l('要在此处显示的消息。'));
返回 $success_message.form 内容和其他输出
推荐阅读
- reactjs - 通过 ui 触发动作的行为与使用键事件处理时不同
- flutter - CheckBox - 完成该商店的工作后,在商店列表上显示一个勾号
- app-actions - 有没有办法在控制台中了解我的应用操作审核状态?
- java - 从 URL 下载 pdf 文件并将其保存在 android (java) 的特定文件夹中
- express - Nuxt/Express API 在控制台而不是浏览器中返回
- javascript - 未捕获的 ReferenceError:我的函数未在 HTMLInputElement.onclick 中定义
- html - CSS嵌套类不能直接选择?
- ionic-framework - 单击按钮后无法路由到下一页
- excel - 需要在创建后立即激活文本框而不调用其名称
- mongodb - MongoDB 从其他集合中获取数组中最常用的类别以及计数