【问题标题】:Create a Cancel button for Joomla 3.2 custom component为 Joomla 3.2 自定义组件创建一个取消按钮
【发布时间】:2014-03-26 14:23:14
【问题描述】:

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

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

这是针对组件“helloworld”和视图“goodbye”的。有人可以查看我的文件并告诉我如何让“取消”按钮起作用吗?我只是想让它关闭当前页面并返回到默认组件页面。

感谢您的帮助。

/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
{

}

【问题讨论】:

    标签: joomla-extensions joomla3.0


    【解决方案1】:

    取决于您想要实现的操作 添加到控制器

        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');
            }
    

    【讨论】:

      【解决方案2】:

      将 HelloWorldViewGoodbye 更改为 GoodbyeViewGoodbye 等。

      【讨论】:

        猜你喜欢
        • 2014-06-12
        • 2014-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-26
        • 2012-11-26
        • 2016-04-29
        • 2013-03-05
        相关资源
        最近更新 更多