我做这个教程: http://www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html需要帮助理解Request()方法Zend框架
我们正在建设使用POST一个简单的输入表单并提交到MySQL数据库。一切工作正常。我只是试图让我的头在getRequest()函数周围。
在控制器方面,我们有这样的:
public function registerAction()
{
$request = $this->getRequest();
$this->view->assign('action',"process");
$this->view->assign('title','Member Registration');
$this->view->assign('label_fname','First Name');
$this->view->assign('label_lname','Last Name');
$this->view->assign('label_uname','User Name');
$this->view->assign('label_pass','Password');
$this->view->assign('label_submit','Register');
$this->view->assign('description','Please enter this form completely:');
}
,然后在视图:
<form name="register" method="post" action="<?php echo $this->escape($this->action)?>">
<table>
<tr>
<td><?php echo $this->escape($this->label_fname)?></td>
<td><input type="text" name="first_name"></td>
</tr>
<tr>
<td><?php echo $this->escape($this->label_lname)?></td>
<td><input type="text" name="last_name"></td>
</tr>
<tr>
<td><?php echo $this->escape($this->label_uname)?></td>
<td><input type="text" name="user_name"></td>
</tr>
<tr>
<td><?php echo $this->escape($this->label_pass)?></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="submit" name="submit" value="<?php echo $this->escape($this->label_submit);?>">
</form>
所以我不明白的是,为什么我们需要一个Request()方法,如果我已经有方法=“后”和行动设置?如果我将它评论出来,脚本并不是网络。我看到它是需要的,但我不明白为什么 - 特别是因为$ request变量似乎没有被使用?
不久你应该看看Zend_Db_Table_Abstract类。它有处理SQL语句的方法,所以你不必自己推出。本教程中的代码适用于SQL注入攻击。 – 2010-06-25 04:58:55
@彼得 - 我相信那是下一个教程 - 他开始寻找其他方式来提供Db。 – Joel 2010-06-25 05:02:42
很酷,你可能也会喜欢Zend_Form,它使用填充值填充表单。 – 2010-06-25 05:43:09