朋友您好我是zf2的新手。我在控制器中创建一个动作,一切正常。当表单有效时,我想将一些值传递给重定向页面。我怎样才能做到这一点?请帮帮我。
我的控制器操作是
public function studenteditAction(){
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('manager', array(
'action' => 'students'
));
}
$form = new StudentsForm();
$request = $this->getRequest();
if ($request->isPost()) {
$students = new Students();
$form->setData($request->getPost());
if ($form->isValid()) {
$students->exchangeArray($form->getData());
$table = $this->getServiceLocator()->get('Students\Model\StudentsTable');
$table->profileStudents($students);
return $this->redirect()->toRoute('manager',array('controller'=>'manager','action'=>'student-view','id'=>$id,'status' => 'profile-ready'));
}
}
return array(
'id' => $id,
'form' => $form,
);
}
我无法在控制器的视图中获取传递的状态值。
'status' => 'profile-ready'
提前致谢
答案 0 :(得分:1)
您需要修改路由配置以接受“id”和“status”值。
'manager' => array(
'type' => 'Segment',
'options' => array(
'route' => '/manager[/:id][/:status]',
'defaults' => array(
'controller' => 'Application\Controller\Manager',
'action' => 'studentView',
),
'constraints' => array(
'id' => '[0-9]*',
'status' => '[a-z-]*'
),
),
),
<强>控制器:强>
public function studentViewAction()
{
$id = $this->params()->fromRoute('id');
$status = $this->params()->fromRoute('status');
return new ViewModel(array('id' => $id, 'status' => $status));
}
查看强>
<?php
echo $this->id;
echo $this->status;
?>
这就是我将所需值传递给另一个控制器的动作
的方法