2013-12-20 87 views
1

我想做一個插入更新刪除網格,但當我點擊更新鏈接數據不會形成。這是我的代碼。數據不會從數據庫進入形式

<?php 
public function editAction() { 

    $form = new Application_Form_user(); 
    $this->view->form = $form; 

    if ($this->getRequest()->isPost()) { 

     $formData = $this->getRequest()->getPost(); 
     if ($form->isvalid($formData)) { 
      $client = new Application_Model_DbTable_Client(); 
      $firstname = $form->getvalue('firstname'); 
      $lastname = $form->getvalue('lastname'); 
      $email = $form->getvalue('email'); 
      $client->updateclient($id, $firstname, $lastname, $email); 
      $this->_helper->redirector('index'); 
     } else { 
      $this->populate($formData); 
     } 
    } else { 

     $id = $this->getRequest()->getparam('id'); 
     if ($id > 0) { 

      $client = new Application_Model_DbTable_Client(); 
      $clients = $client->getClient($id); 

      $this->populate($clients); 
     } 
    } 
} 

我的模型代碼: -

<?php 

class Application_Model_DbTable_Client extends Zend_Db_Table_Abstract { 

    protected $_name = 'client'; 

    public function getClient($id) { 
     global $db; 
     $query = $db->select()->from('client'); 
     if ($id > 0) { 
      $query->where('Id=?', $id); 
     } 
     $data = $db->fetchAll($query); 
     return $data; 
    } 

    public function addClient() { 
     print_r($data); 
     die; 
     $data = array('fisrtname' => 'firstname', 
      'lastname' => 'lastname', 
      'email' => 'email'); 
     $this->insert($data); 
    } 

    public function updateClient() { 
     $data = array('fisrtname' => 'firstname', 
      'lastname' => 'lastname', 
      'email' => 'email'); 
     $this->update($data, 'Id=' . $id); 
    } 
+0

考慮[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)回答是否對你有幫助。 –

回答

1

你爲什麼不抓在模型的任何參數?

如果你不抓住它們,它將如何獲得價值!

使用此,

public function updateclient($id, $firstname, $lastname, $email) { 
     $data = array('fisrtname' => $firstname, 
      'lastname' => $lastname, 
      'email' => $email); 
     $this->update($data, 'Id=' . $id); 
    } 

還用於將數據填充到形式使用,

$form->populate$this->populate ..

+0

感謝您的回覆,它真的幫了我。 – Tuhin

+0

不客氣..也歡迎來到SO。 –