php - 如何将安装错误返回到 Prestashop 1.7 中的模块管理器?
问题描述
我正在尝试调试我的模块安装,其中几次它会根据某些字段返回 false。根据哪个失败,我想显示一个输出。我试过了:
\Tools::displayError('This worked.');
array_push($this->context->controller->errors, $this->l('This worked.'));
我的安装如下所示:
public function install() {
\Tools::displayError('This worked.');
array_push($this->context->controller->errors, $this->l('This worked.'));
return (parent::install() && false); // Force a fail to test
}
但是,我似乎得到的只是:
Unfortunately, the module did not return additional details.
我在互联网上寻找修复,但只遇到过时的。任何帮助,将不胜感激。
编辑:我的构造函数将 need_instance 设置为 1:
public function __construct() {
...
$this->need_instance = 1;
...
parent::__construct();
...
}
更新:为了帮助以后的查看者,该类的insert
功能会Db
自动为表名添加前缀。删除已self::DB_PREFIX
修复的此问题。
return \Db::getInstance()->insert('iezon_portfolio', array(
'img_link' => pSQL($img),
'title' => pSQL($title),
'description' => pSQL($description),
'company_name' => pSQL($company),
'company_url' => pSQL($company_url),
'testimonial' => pSQL($testimonial),
'is_favourite' => (int) $fav,
));
解决方案
尝试这样的事情:
public function install()
{
if ($this->checkForErrors()) {
$this->_errors[] = $this->l('Error message');
return false;
}
...rest of the code...
}
推荐阅读
- php - Validate Unique - 传递给 Illuminate\Validation\Factory::make() 的 TypeError 参数 1 必须是数组类型,给定 null
- reactjs - 如何将日历图标放入右侧的日期选择器
- authentication - 将 nginx 配置为基于用户身份验证的服务器静态文件
- node.js - 我可以在节点中部署 Spring RESTful Web 应用程序吗
- java - 如何修复 Android Studio 上的 gradle 错误
- autodesk-forge - model.publish 事件是否仅在 Revit 发布操作期间发生?
- reactjs - react HOC中的@是什么?
- spring - @Bean 和可选的 @Autowire
- c++ - std::hardware_constructive_interference_size 有用吗?
- c# - 如何获取表单打开事件(WinForm)?