I am new to Zend framework and I am trying to update data in database and grid, but instead of updating particular row all rows are getting updated. please help me with this.
Here is my controller code.
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 = $formData['firstname'];
$lastname = $formData['lastname'];
$email = $formData['email'];
$client->updateClient('Id',$firstname,$lastname,$email);
$this->_helper->redirector('index');
}
else
{
$form->populate($formData);
}
}
else
{
$id=$this->getRequest()->getparam('id');
if($id>0)
{
$client= new Application_Model_DbTable_Client();
$clients = $client->getClient('Id');
$form->populate($clients[0]);
}
}
}
And here is my model code.
public function updateClient($id,$firstname,$lastname,$email)
{
$data=array('firstname'=>$firstname,
'lastname'=>$lastname,
'email'=>$email);
$this->update($data,"Id=$id");
}
try to change your code, so it looks like this:
if($form->isvalid($formData))
{
$client= new Application_Model_DbTable_Client();
$firstname = $formData['firstname'];
$lastname = $formData['lastname'];
$email = $formData['email'];
$id=$this->getRequest()->getparam('id'); // define your id
$client->updateClient($id,$firstname,$lastname,$email); // here, change Id into proper $id
$this->_helper->redirector('index');
}