嗨, 
我一直在尝试很多选择来管理异常,并在管理面板上显示错误,但似乎没有工作。
我正在使用自定义模块的后进程方法。用户通过表单发送CSV文件并检查数据后(这里一切正常),如果发生异常,我需要显示一条消息,停止并重定向到同一页面。 
我已经尝试过: 
this->get('session')->getFlashBag()->add('error',$msg);
Tools::redirectAdmin('index.php?controller='.$controller.'&token='.$token);
这个: 
header("HTTP/1.0 400 Bad Request");
die(json_encode(array( 'error' => array($this->l(' Error') ))));
(一个人可以使用,但显示了一个带有消息的空白页,而不是管理面板内的消息) 
也是这样: 
$this->context->smarty->assign(array(
'token' => Tools::getAdminTokenLite('AdminModules'),
'errors' => $this->errors
));
$this->setTemplate('ExcelProcess.tpl');
和{$ errors | var_dump}在tpl显示null ...
和许多其他选项。 
我找不到关于PS文档的退回式自定义通知的任何内容,只有关于前面的自定义通知。
有任何线索吗? 
 
非常感谢! 
MIGUEL
邮政编码代码:
Tpl code:
Hi,
I've been trying a lot of options to manage an exception and show an error at admin panel but nothing seems to work.
I'm at the postProcess method of a custom module. After the user sends a csv file through a form and the data is checked (everything works fine here), if an exception occurs I need to show a message, stop and redirect to the same page.
I've tried this:
this->get('session')->getFlashBag()->add('error',$msg);
Tools::redirectAdmin('index.php?controller='.$controller.'&token='.$token);
this:
header("HTTP/1.0 400 Bad Request");
die(json_encode(array( 'error' => array($this->l(' Error') ))));
(that one works but shows a blank page with the message, not the message inside the admin panel)
also this:
$this->context->smarty->assign(array(
'token' => Tools::getAdminTokenLite('AdminModules'),
'errors' => $this->errors
));
$this->setTemplate('ExcelProcess.tpl');
and {$errors|var_dump} at the tpl displays null...
... and many other options.
I can't find anything either about backoffice custom notifications at the PS docs, only about front custom notifications.
Any clue?
Thanks a lot!
Miguel
PostProces code: https://drive.google.com/file/d/175nhUPDlzi6T8rZjjE8Desnzq-mtYzNQ/view?usp=sharing
Tpl code: https://drive.google.com/file/d/17EONOCJ60L4Gp_GidzvwCQwMyTrRXapF/view?usp=sharing
发布评论
评论(1)
添加 postprocess()中的错误
可以通过设置或
在表单提交检查中 。
您的错误消息将渲染到红色框中。
如果要显示警报而不重新加载页面,则必须对AdminController执行Ajax调用,恢复JSON响应并呈现错误消息,导致呼叫的执行。
参见
Adding an error in postProcess() can be achieved by setting
or
during your form submission checks.
Form will be rendered with your error messages into a red box.
If you want to show an alert without reloading the page instead, you'll have to perform an AJAX call to your AdminController, get back a JSON response and render your error message as a result of the execution of the call.
See offical docs