2014-02-24 54 views
0

我正在嘗試構建一個Joomla 3.2自定義組件,並且在取消按鈕(管理部分)的工作時遇到困難。我已經添加的按鈕,但是當我點擊它,我得到的錯誤:爲Joomla 3.2自定義組件創建一個Cancel按鈕

0 Invalid controller: 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> 

/管理者/控制器/ 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 
{ 

} 

回答

1

變化HelloWorldViewGoodbye到GoodbyeViewGoodbye和其它相同。

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