0
我是一個使用zf2的新手,我正在按照相冊控制器教程。當添加相冊時,瀏覽器將停留在具有空白html頁面的album/add(url)上,而不是重定向到/ album/index。你能告訴我會發生什麼嗎?我在某處忘記了一個參數?重定向是否真的重定向? 這是代碼:Zend Framework 2重定向似乎工作,但沒有任何反應(不重定向)
控制器專輯:
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',
),
),
),
),
),