为什么Zend数据库更新没有发布


Why is Zend DB Update not posting?

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

在这里,我使用模型映射器尝试更新行集,如 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
    }
}

是不是少了点什么?

试试这个

$where =   $this->getDbTable()->getAdapter()->quoteInto('id = ?', $id);
 $this->getDbTable()->update($data, $where);