-1

应用程序中的其他模块正在更新,除了这个。

在这里,我使用模型映射器尝试更新行集,如http://framework.zend.com/manual/en/learning.quickstart.create-model.html

 public function SomeAction()
 {
   $mapper = new Application_Model_SomeMapper();
   $model = new Application_Model_SomeModel(); //getters and setters

   // action body
   $request = $this->getRequest();
   $data = $this->_request->getParams();
   $someId = $data['someid'];

   $get = $mapper->find($someId, new Application_Model_SomeModel, true); //find the row by id, and return array

/*
instantiating a form object and adding "submit" 
*/
   $form = new Module_Form_FormName();
   $form->setAction("/module/controller/action/params/$someId");
   $form->setMethod('post');
   $form->setName('some_edit');

   $submit = $form->createElement('button', 'submit');
   $submit->setAttrib('ignore',true);
   $submit->setLabel('Edit Something');
   $form->addElement($submit);


if ($this->_request->isPost())
    {
        if($form->isValid($request->getPost()))
        {
            $data = $this->_request->getPost();

            if(empty($data['some_id' ]))
            {
                $data['tier_models_id'] = NULL;
            }

            unset($data['submit']);

            $setters = $model->setId($data['id'])
                             ->setField1($data['field_1']); 

            if ($mapper->save($someId, $setters)) 
            {
                $this->_redirect("/index/");                  
            }
        }      
    }


    $form->populate($tier);
    $this->view->form = $get;

}

这是保存映射器函数的示例,除了我包含了一个额外的 $id 参数

public function save(Application_Model_Guestbook $guestbook)
{
    $data = array(
        'email'   => $guestbook->getEmail(),
        'comment' => $guestbook->getComment(),
        'created' => date('Y-m-d H:i:s'),
    );

    if (null === ($id = $guestbook->getId())) {
        unset($data['id']);
        $this->getDbTable()->insert($data);
    } else {
        $this->getDbTable()->update($data, array('id = ?' => $id)); //not happening, although the 'id' is passed as a param
    }
}

有什么遗漏吗?

4

1 回答 1

0

试试这个

$where =   $this->getDbTable()->getAdapter()->quoteInto('id = ?', $id);
 $this->getDbTable()->update($data, $where);
于 2012-05-16T15:09:33.303 回答