2010-06-17 65 views
0

以下是我的Controller類的一些示例方法。現在當用戶點擊New按鈕時,$ task = add被髮送給Controller,並調用add()方法。正如你所看到的,它並沒有做任何事情,它只是創建一個url並將其轉發給正確的視圖。這是以MVC模式做事的正確方法嗎?Joomla轉發代碼到視圖...這是正確的方法嗎?

/** 
* New button was pressed 
*/ 
function add() { 
    $link = JRoute::_('index.php?option=com_myapp&c=apps&view=editapp&cid[]=', false); 
    $this->setRedirect($link); 
} 


/** 
* Edit button was pressed - just use the first selection for editing 
*/ 
function edit() { 
    $cid = JRequest::getVar('cid', array(0), '', 'array'); 
    $id = $cid[0]; 
    $link = JRoute::_("index.php?option=com_myapp&c=apps&view=editapp&cid[]=$id", false); 
    $this->setRedirect($link); 
} 

回答

0

我不認爲這是正確的方法。我會建議看看一些核心Joomla!代碼來看看它是如何完成的。我總是看到一個偉大而簡單的例子,就是Weblinks。看看他們在控制器的編輯功能做什麼:

... /組件/ com_weblinks /控制器/ weblink.php

function edit() 
    { 
      $user = & JFactory::getUser(); 

      // Make sure you are logged in 
      if ($user->get('aid', 0) < 1) { 
        JError::raiseError(403, JText::_('ALERTNOTAUTH')); 
        return; 
      } 

      JRequest::setVar('view', 'weblink'); 
      JRequest::setVar('layout', 'form'); 

      $model =& $this->getModel('weblink'); 
      $model->checkout(); 

      parent::display(); 
    } 

他們設定的視野和佈局變量,然後調用parent :: display讓Joomla!出去並顯示該視圖/佈局。

+0

你知道什麼weblinks edit()方法給我,我的不? – jax 2010-06-20 02:42:21

相關問題