致命错误:在 joomla 中调用未定义的方法 JToolbarHelper::d eleteListX()


Fatal error: Call to undefined method JToolbarHelper::deleteListX() in joomla

protected function addToolBar() 
{
    JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'), 'helloworld');
    JToolBarHelper::deleteListX('', 'helloworlds.delete');
    JToolBarHelper::editListX('helloworld.edit');
    JToolBarHelper::addNewX('helloworld.add');
}

此语法中的错误是什么

根据 Joomla 文档,类 JToolBarHelper 定义在

  • 管理员/包含/工具栏.php

但是,该类中没有这样的方法。 检查提交历史记录显示该方法已在

  • 480a506c80 - 从 JToolBarHelper 中删除已弃用的 CMS 代码

因此,如果您收到此错误,则您的代码是为旧版本的Joomla编写的。

deleteListX的代码是这样的:

/**
 * Writes a common 'delete' button for a list of records.   
 * Extended version of deleteList() calling hideMainMenu() before Joomla.submitbutton().    
 *  
 * @param   string $msg Postscript for the 'are you sure' message.  
 * @param   string $task An override for the task.  
 * @param   string $alt An override for the alt text.   
 * @since   1.0     
 * @deprecated  
 */     
 static function deleteListX($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')     
 {  
    self::deleteList($msg, $task, $alt);    
 }

如您所见,它只是包装对deleteList的调用,定义为

/**
* Writes a common 'delete' button for a list of records.
*
* @param    string $msg Postscript for the 'are you sure' message.
* @param    string $task An override for the task.
* @param    string $alt An override for the alt text.
* @since    1.0
*/
public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')

因此,您可以更换您的

JToolBarHelper::deleteListX('', 'helloworlds.delete');

通过直接呼叫

JToolBarHelper::deleteList('', 'helloworlds.delete')

请注意,editListXaddNewX也已删除。因此,您将获得相同的错误。检查已删除的源代码并根据需要调整方法。