我正在编写一个 Joomla! 1.7 组件的安装脚本。如何修改脚本中的
目前,我只从
install()
部分,以便在失败时向用户显示格式良好的 HTML 错误信息?目前,我只从
install()
程序返回 false
,这会导致一个晦涩难懂的错误消息:
组件安装:自定义安装程序失败
joomla/installer/adapters/component.php
中的 component.php 文件具有以下代码,这让我怀疑我无法更改 abort()
消息。if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'install'))
{
if ($this->parent->manifestClass->install($this) === false) {
// Install failed, rollback changes
$this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_COMP_INSTALL_CUSTOM_INSTALL_FAILURE'));
return false;
}
}
解决方案
在返回错误之前,我可以引发一个错误,该错误会以黄色框的形式出现。
JError::raiseNotice(1, "Error Message <html code>");
return false;