我对zend框架很新。我想在if条件中声明一个表单对象。但我不知道是不是可能?我写下面的代码:
public function editAction()
{
$modelUsers = new Model_Users();
$userId = $this->_getParam('userId');
if ($userId) {
$populateData = array();
$user = $modelUsers->fetch($userId);
// print_r($user); exit();
if ($user instanceof Model_User) {
$populateData = $user->toArray();
$form = $this->_geteditForm($user->email);
}
$form->populate($populateData);
}
$request = $this->getRequest();
if ($request->isPost()) {
请让我知道我是否会去写路径。
提前致谢
答案 0 :(得分:1)
没关系,但是(假设它是某种形式)最好重新定向到列表或在ID丢失时抛出异常。比你不需要在条件下关闭整个表格。即:
if (!$userId = $this->_getParam('userId')) {
throw new Exception('Missing userId');
//or
$this->_helper->redirector('index');
}