2013-10-05 22 views
0

我製作了joomla 2.5(在Joomla 3中工作)組件。爲了測試組件,我創建了一個菜單項「mycomtest-main」,並將組件放置在該菜單項中。完整的本地測試網址是「localhost/joomla/mycomtest-main」。組件列出了很多項目,並且當單擊條目窗體顯示時有一個按鈕,這是我的那個mvc組件的入口窗體視圖,url變成了「localhost/joomla/mycomtest -main?task = edit & id = 4「,因爲我使用JRoute :: _(」index.php?...「)來保存sef url.So在上面的表單填寫並提交之後,它被重定向回默認值view - localhost/joomla/mycomtest-main,但不幸的是url變成了 - localhost/joomla/component/mycomtest-main /而不是localhost/joomla/mycomtest-main。我的組件報名表視圖外觀如下 -無法在joomla mvc組件中正確實現jroute功能

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data"> 
    <input type="hidden" name="option" id="option" value="<?php echo $_REQUEST['option']; ?>" /> 
    <input type="hidden" name="task" id="task" value="save" /> 
    <input type="hidden" name="id" id="id" value="<?php if($row!=NULL){ echo $row->id; }?>" /> 
    <input type="hidden" name="page" id="page" value="<?php echo JRequest::getVar('page'); ?>" /> 
.............rest of the html contents along with submit button 
</form> 

而且在我的MVC組件的Controller.php這樣的文件我用JROUTE通過這一方法 -

function save() 
    { 
     $model = $this->getModel('entry'); 
     if($model->store()) 
     { $msg = "saved successfully"; $type = 'message'; } 
     else 
     { $msg = 'error found'; $type = 'error'; 
     } 
     $urlSet=JRoute::_("index.php?option=". $_REQUEST['option'].""); 
     $this->setRedirect($urlSet, $msg, $type); 
} 

所以,我怎麼去讓後進入查看錶單提交我被重定向到菜單項頁面 正確的URL在下面? -

http://localhost/joomla/mycomtest-main/ 

請儘快幫忙

回答

0

那是因爲你沒有建立該組件的路由器。你可以檢查位於內部的元件/ com_user的router.php或寫你自己的路由遵循這一http://docs.joomla.org/Routing

,或者你可以使用你每一次做這樣的重定向:

$menu = $app->getMenu(); 
     $items = $menu->getItems('component', 'com_yourcom'); 
     $itemid = JRequest::getint('Itemid'); 
     for ($i = 0, $n = count($items); $i < $n; $i++) { 
     // Check to see if we have found the resend menu item. 
     if (!empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'yourview')) { 
      $yourviewid = $items[$i]->id; 
     } 
     } 
$redirect = JRoute::_("index.php?option=com_yourcom&Itemid=".$yourviewid ,false); 
     $this -> setRedirect($redirect);