如何在zend框架中设置表单元素值进行编辑

时间:2014-10-16 10:45:53

标签: zend-framework

我正在使用zend框架。我已完成用户注册和登录,但我无法更新用户信息,因为我不知道如何以更新形式显示表单元素值。请告诉我任何解决方案。

1 个答案:

答案 0 :(得分:1)

    $editClientForm = new Form_AddNewClientForm();
    $editClientForm->setAction($this->view->baseUrl().'/client/edit');
    //fetch client data from your database through model
    $clientInfo = $mdlClient->fetchClientDetails($id);
    //populate the data to form
    $editClientForm->populate($clientInfo); 
    $this->view->editClientForm = $editClientForm;

更新

建议@ php-dev:

之后
    $editClientForm = new Form_AddNewClientForm();
    $editClientForm->setAction($this->view->baseUrl().'/client/edit');
    //fetch client data from your database through model
    $mdlClient = new Model_Client();
    $clientInfo = $mdlClient->fetchClientDetails($id);
    //populate the data to form
    $editClientForm->populate($clientInfo); 
    $this->view->editClientForm = $editClientForm;

在你的模特里面:

    public function fetchClientDetails($id) 
    {
      $row = $this->_db->fetchRow("SELECT * from tablename where id = $id");        

      return $row;
    }