2014-01-30 50 views
0

我有以下的module.config.php配置Zend的重定向不工作

'router'=>array(
     'routes'=>array(
       'test'=>array(
         'type'=>'Zend\Mvc\Router\Http\Literal', 
         'options'=>array(
           'route'=>'/test', 
           'defaults'=>array(
             'controller'=>'Test\Controller\Index', 
             'action'=>'index' 
           ) 
         ), 
         'may_terminate' => true, 
         'child_routes' => array(
           'edit' => array(
             'type' => 'segment', 
             'options' => array(
               'route' =>'/edit[/:id]', 
               'constraints' =>array('id' => '[\d\w\-_]*'), 
               'defaults' => array(
                 'controller' =>'Test\Controller\Index', 
                 'action' => 'edit', 
               ), 
             ), 
           ), 
           'add' => array(
             'type' => 'segment', 
             'options' => array(
               'route' =>'/add', 
               'defaults' => array(
                 'controller' =>'Test\Controller\Index', 
                 'action' => 'add', 
               ), 
             ), 
           ), 
         ), 
       ) 
     ) 
) 
現在

我使用以下重定向

回報$這個 - >重定向() - > toRoute( '測試') ;

它不起作用。我沒有得到什麼不對這個

+0

你說的「不工作」的意思。你有什麼錯誤嗎?頁面是否正常顯示?你有空的頁面嗎?我們需要更多信息。 –

+0

我在調用保存功能後重定向頁面。功能正常執行。字段反映在數據庫中。但瀏覽器顯示相同的頁面,它不會重定向到所需的位置。 –

+0

好的。你能告訴我們實際的代碼嗎?這個配置對我們來說不是很有幫助。 –

回答

0

您的配置文件是這裏不多的幫助,你應該已經張貼您的控制器的代碼,不過,

,而不是return $this->redirect()->toRoute('test');

使用以下格式

return $this->redirect()->toRoute('ModuleName', 
    array('controller'=>controllerName, 
     'action' => actionName, 
     'params' =>params)); 

哪裏ModuleName是你module, 哪裏ControllerName是你controller名,01名其中Action名稱是您的名稱action

注意: - params是可選的。

0

如果模塊名稱是測試,那麼你有嘗試:

return $this->redirect()->toUrl('/test');