如何在安装Joomla时显示自定义错误!1.6-1.7组件


How to show custom error while installing a Joomla! 1.6 - 1.7 component?

我正在为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;

解决方案

在返回错误之前,我可以提出一个错误,它很好地显示在黄色框中。

JError::raiseNotice(1, "Error Message <html code>");
return false;