我必须更新Symfony中的多个列,但我无法找到解决方案...... 所以,我想以这种方式做到这一点:
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set('q.login_name','?','John')
->where('q.webuser_id=?',1)
->execute();
好的,这可以,但我必须用几个列来做。 我试过这样的东西,但它不起作用:
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set('q.login_name,q.name','?','kaka,pisa')
->where('q.webuser_id=?',1)
->execute();
答案 0 :(得分:14)
尝试:
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set('q.login_name', 'John')
->set('q.name', 'Another value')
->where('q.webuser_id=?',1)
->execute();
答案 1 :(得分:1)
尝试
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set(array('q.login_name' => 'John',
'q.name' => 'Another value'))
->where('q.webuser_id=?',1)
->execute();
答案 2 :(得分:0)
class contentActions extends sfActions {
const TABLE_NAME_ARTICLE = 'article';
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request) {
// Get id from $_GET
$id = $request->hasParameter('id') ? $request->getParameter('id') : $request->getPostParameter(self::TABLE_NAME_ARTICLE . '[id]');
// Create model active row by id
$modelActiveRow = Doctrine::getTable(self::TABLE_NAME_ARTICLE)->find($id);
// Verify existence article
$this->forward404Unless($modelActiveRow);
// Get form name
$formName = self::TABLE_NAME_ARTICLE . 'Form';
// Create article form object. Use model article (load data).
$this->form = new $formName($modelActiveRow);
if ($request->isMethod('post')) {
$postData = $request->getParameter(self::TABLE_NAME_ARTICLE);
$this->form->bind($postData);
if ($this->form->isValid()) {
$this->form->save();
$this->getUser()->setFlash('notice', 'Changes were successfully saved.');
// redirect
}
}
}
}