Joomla JToolbarhelper按钮不起作用



我正在创建自定义组件,但我无法让我的工具栏工作。

查看.html.php:

protected function addToolbar() {
    JToolBarHelper::title( JText::_('COM_CYCLIST_TITLE_CATEGORIES'), 'generic.png' );
    $bar = & JToolBar::getInstance('toolbar');
    $bar->appendButton( 'Link', 'new', 'JTOOLBAR_NEW', '/administrator/index.php?option=com_project&view=project&layout=edit');
    JToolbarHelper::addNew( 'project.add');
    JToolBarHelper::editList('project.edit');
    JToolBarHelper::deleteList('', 'projects.delete');
//        $bar->appendButton( 'Link', 'custom', 'Custom', '../index.php?option=com_mycomponent&format=raw' );
    }

控制器项目.php:

<?php
// No direct access.
defined('_JEXEC') or die;
jimport('joomla.application.component.controlleradmin');
class ProjectControllerProject extends JControllerForm {
    public function __construct() {
        parent::__construct();
    }
}
?>

我为工具栏按钮提供什么任务并不重要。当我按下te按钮时,它会打开组件url,但它显示404。当我在新选项卡中复制/粘贴 url 时,将显示概述。

http://localhostproject/administrator/index.php?option=com_project&view=projects

我错过了什么?

管理员组件:https://bitbucket.org/LightPhoenix/com_project/src

尝试将 addToolbar 函数更改为

protected function addToolbar() {
    JToolBarHelper::title( JText::_('COM_CYCLIST_TITLE_CATEGORIES'), 'generic.png' );
    $app = JFactory::getApplication();
    // Run in backend
    if ($app->isAdmin() === true)
    {
        $bar = JToolBar::getInstance('toolbar');
        $url = JRoute::_('index.php?option=com_project&view=project&layout=edit');
        $bar->appendButton( 'Link', 'new', 'JTOOLBAR_NEW', $url);
    }
    JToolbarHelper::addNew( 'project.add');
    JToolBarHelper::editList('project.edit');
    JToolBarHelper::deleteList('', 'projects.delete');
    //$bar->appendButton( 'Link', 'custom', 'Custom', '../index.php?option=com_mycomponent&format=raw' );
}

可能是您的网址不正确,因此您会收到 404 错误。如果您使用 JRoute,如果您使用的是 sef url,它将为您修复 url。$app->isAdmin() 是检查您是否处于管理员模式。

该弹出窗口的网址似乎不正确。你应该对 Urls 使用 joomla 方法或从 index 开始.php .如果我正确理解,下面的代码将为您工作 -

$bar->appendButton( 'Link', 'new', 'JTOOLBAR_NEW', Juri::base(true) . '/index.php?option=com_project&view=project&layout=edit');

$bar->appendButton( 'Link', 'new', 'JTOOLBAR_NEW', 'index.php?option=com_project&view=project&layout=edit');

最新更新