【问题标题】:Zend Framework 2 Redirect seems to work but nothing happens (no redirection)Zend Framework 2 Redirect 似乎有效,但没有任何反应(无重定向)
【发布时间】:2014-11-06 14:31:24
【问题描述】:

我是使用 zf2 的新手,我正在使用专辑控制器学习教程。添加相册时,浏览器不会重定向到 /album/index,而是停留在带有空白 html 页面的相册/add (url) 上。你能告诉我会发生什么吗?我在某处忘记了一个参数?重定向真的重定向吗? 这是代码:

控制器相册:

public function addAction() {
$form = new AlbumForm();
$form->get('submit')->setValue('Add');

$request = $this->getRequest();
if ($request->isPost()) {
  $album = new Album();
  $form->setInputFilter($album->getInputFilter());
  $form->setData($request->getPost());

  if ($form->isValid()) {
    $album->exchangeArray($form->getData());
    $this->getAlbumTable()->saveAlbum($album);

    // Redirect to list of albums
    return $this->redirect()->toRoute('album',array('controller'=>'album', 'action'=>'index'));
  }
}
return array('form' => $form);

}

路线:

'router' => array(
    'routes' => array(
        'album' => array( // album is the name of the route. Tout url localhost/album...
            'type' => 'segment',
            'options' => array(
                'route' => '/album[/][:action][/:id]', // ...matchera l'action correspondante dans le controlleur...
                'constraints' => array(               // ...index est l'action par defaut si pas d'action renseignée dans l'url
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

【问题讨论】:

    标签: redirect zend-framework


    【解决方案1】:

    解决了!这与 ZF2 无关。由于另一个原因,我不得不重新安装 Wampserver,现在一切正常!!但我不知道它失败的确切原因。

    【讨论】:

      猜你喜欢
      • 2021-10-16
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      相关资源
      最近更新 更多