为Joomla 3.2自定义组件创建“取消”按钮

时间:2014-02-24 18:28:28

标签: joomla-extensions joomla3.0

我正在尝试构建一个Joomla 3.2自定义组件,并且很难让取消按钮(管理部分)工作。我添加了按钮,但是当我点击它时,我收到错误:

  

0无效的控制器:name ='helloworld',format =''

这是组件'helloworld'和视图'再见'。有人可以查看我的文件并告诉我如何让“取消”按钮工作吗?我只是希望它关闭当前页面并返回默认组件页面。

感谢您的帮助。

/administrator/views/goodbye/view.html.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 */
class HelloWorldViewGoodbye extends JViewLegacy
{
    // Overwriting JView display method
    function display($tpl = null)
    {
        $this->addToolbar();
        // Display the view
        parent::display($tpl);
    }

        protected function addToolbar()
    {
            JToolbarHelper::title('Race Results','tbar');
            JToolbarHelper::cancel('helloworld.cancel', 'JTOOLBAR_CLOSE');
        }
}

/administrator/views/goodbye/tmpl/default.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<h1>Cancel Race Results</h1>

<script type="text/javascript">
    Joomla.submitbutton = function(task)
    {
        if (task == 'helloworld.cancel')
        {
            Joomla.submitform(task, document.getElementById('helloworld-form'));
        }
    }
</script>

<form id="helloworld-form" name="adminForm" method="post" action="<?php echo JRoute::_('index.php?option=com_helloworld&view=goodbye'); ?>">

    <input type="hidden" name="option" value="com_helloworld" />
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="view" value="goodbye" />
    <?php echo JHtml::_('form.token'); ?>

</form>

/administrator/controllers/goodbye.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla modelitem library
jimport('joomla.application.component.controller');

/**
 * HelloWorld Model
 */
class HelloWorldControllerGoodbye extends JControllerLegacy
{

    public function edit() {

    }

    public function add() {

    }

    public function remove() {

    }

    public function save() {

    }

    public function apply() {

    }

}

/administrator/models/goodbye.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla modelitem library
jimport('joomla.application.component.model');

/**
 * HelloWorld Model
 */
class HelloWorldModelGoodbye extends JModelLegacy
{

}

2 个答案:

答案 0 :(得分:2)

取决于您希望实现的行动 添加到控制器

    public function cancel($key = null) {
    JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

    $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view=name_of the_view' , false));
    return true;
}

在view.html中为按钮添加条件

    if (condition when to use button)
        {
        JToolbarHelper::cancel('your_controller_name.cancel');
        }
    else
        {
        JToolbarHelper::cancel('your_controller_name', 'JTOOLBAR_CLOSE');
        }

答案 1 :(得分:1)

将HelloWorldViewGoodbye改为GoodbyeViewGoodbye和其他人。