2011-01-26 50 views
5

我必須更新Symfony的多列,但我無處找到解決辦法...... 所以,我想去做這樣:更新多個列中的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(); 

回答

14

嘗試:

$q = Doctrine_Query::create() 
    ->update('WebusersTable q') 
    ->set('q.login_name', 'John') 
    ->set('q.name', 'Another value') 
    ->where('q.webuser_id=?',1) 
    ->execute(); 
+0

哇!這樣可行!非常感謝你! :) – kungfucsiga 2011-01-26 10:36:51

1

嘗試

$q = Doctrine_Query::create() 
->update('WebusersTable q') 
->set(array('q.login_name' => 'John', 
      'q.name' => 'Another value')) 
->where('q.webuser_id=?',1) 
->execute(); 
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 
     } 
    } 

} 

}