如何从URL中检索值?

问题描述:

我的表单编辑:如何从URL中检索值?

$params = array (
    'host' => 'localhost', 
    'username' => 'root', 
    'password' => '', 
    'dbname' => 'my_address_book' 
); 
$db = Zend_Db::factory('PDO_MYSQL', $params); 

$stmt = $db->query('SELECT * FROM user WHERE userName LIKE ?', $name2.'%'); 

while ($row = $stmt->fetch()) 
{ 
    $flag1 = 1; 
    $id = $row['userId']; 

    echo '<table width="300px">'; 
    echo ' 
     <tr> 
      <th align="left">Name</th> 
      <td>:</td> 
      <td align="left">'.$row["userName"].'</td> 
      <td><a href ="Edit?id ="'.$id.'">Edit</a></td> 
     </tr> 
    '; 
    echo ' 
     <tr> 
      <th align="left">Address1</th> 
      <td>:</td> 
      <td align="left">'.$row["addressLine1"].'</td> 
      <td><a href="Delete?id="'.$row['userId'].'">Delete</a></td> 
     </tr> 
    '; 
    echo '</table>'; 
}flag1 = 1; 

$id = $row['userId']; 
echo '<table width="300px">'; 
echo ' 
    <tr> 
     <th align="left">Name</th> 
     <td>:</td> 
     <td align="left">'.$row["userName"].'</td> 
     <td><a href ="Edit?id ="'.$id.'">Edit</a></td> 
    </tr> 
'; 
echo ' 
    <tr> 
     <th align="left">Address1</th> 
     <td>:</td> 
     <td align="left">'.$row["addressLine1"].'</td> 
     <td><a href ="Delete?id="'.$row['userId'].'">Delete </a></td> 
    </tr>'; 
echo '</table>'; 

在我EditController:

if ($this->getRequest()->isPost('$id')){ 
    $form = new Application_Form_Edit1(); 
    $this->view->form = $form; 
} 

但它从来没有进到 “EDIT1” 的形式。
我对Zend很新。我究竟做错了什么?
任何帮助将不胜感激。

+0

它看起来像很多事情都是错误的,它似乎有点难以帮助。你的表单代码是什么? (注意!不要在变量名中使用数字) – markus 2013-02-18 11:01:58

尝试$this->getRequest()->getParam('id')而不是$this->getRequest()->isPost('id')

if (!empty($this->getRequest()->getParam('id'))){ 
    $form = new Application_Form_Edit1(); 
    $this->view->form = $form; 
} 

侧注:尝试通过MVC标准,并将您的HTML到视图。

+0

是的,我愿意......但我不知道该怎么做。 – gecco 2013-02-19 03:30:53

+0

我知道如何获取所有,但选择特定的行很难.. – gecco 2013-02-19 03:31:38

+0

我假设,您的第一个代码块是类Application_Form_Edit1的一部分。如果是,那么应该通过Zend_Form组件构建html代码。请尝试按照[快速入门](http://framework.zend.com/manual/1.12/en/learning.quickstart.html) – 2013-02-19 06:28:03

if ($this->_request->isPost()) { 
     $data = $this->_request->getPost(); //All your data in $data array. print_r($data) it & you will know. 
     $id = (int)$this->_getParam('id'); // get a variable with name = id 
}