简体   繁体   English

需要帮助来了解getRequest()Zend Framework

[英]need help understanding getRequest() Zend Framework

I'm doing this tutorial: http://www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html 我正在做本教程: http : //www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html

We are building a simple input form using POST and submitting it to a mySQL database. 我们正在使用POST构建一个简单的输入表单,并将其提交到mySQL数据库。 All is working fine. 一切正常。 I'm just trying to get my head around the getRequest() function. 我只是想让我了解getRequest()函数。

In the controller, we have this: 在控制器中,我们有:

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:');        
}

and then in view: 然后在视图中:

 <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>

So what I don't understand is why do we need a getRequest() if I already have the method="post" and the action set? 所以我不明白的是,如果我已经有了method =“ post”和操作集,为什么我们需要一个getRequest()? If I comment it out, the script doesn'twork. 如果我将其注释掉,该脚本将不起作用。 I see it's needed, but I don't understand why-especially since the $request variable doesn't seem to be used? 我认为这是必需的,但是我不明白为什么-尤其是因为似乎没有使用$ request变量吗?

In the code you have provided, $request doesn't appear to be used at all. 在您提供的代码中,$ request似乎根本没有使用。 I don't see why commenting it out would break. 我不知道为什么将其删除会中断。

What happens, exactly, when you comment it out? 确切地说,当您注释掉时会发生什么?

The getRequest() function is for getting the Request object, which gives you parameters and such (ie controller, action, etc); getRequest()函数用于获取Request对象,该对象为您提供参数等(例如,控制器,操作等);

EDIT: 编辑:

I had a look at the tutorial, and it has this: 我看了一下教程,它包含以下内容:

12   
13    $sql = "INSERT INTO `user`
14            (`first_name` , `last_name` ,`user_name` ,`password`)
15            VALUES
16            ('".$request->getParam('first_name')."', '".$request->getParam('last_name')."', '".$request->getParam('user_name')."', MD5('".$request->getParam('password')."'))";
17    $DB->query($sql);

You'll note that it uses the $request variable to get the Parameters: 'first_name', 'last_name', 'user_name', 'password' 您会注意到,它使用$ request变量来获取参数:'first_name','last_name','user_name','password'

And saves them into the DB. 并将它们保存到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM