5
votes

I have to update multiple columns in Symfony, but I can nowhere find the solution... So, I'd like to do it in this way:

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

OK, that works, but I have to do it with several columns. I tried something like this, but it doesn't work:

$q = Doctrine_Query::create()
     ->update('WebusersTable q')
     ->set('q.login_name,q.name','?','kaka,pisa')
     ->where('q.webuser_id=?',1)
     ->execute();
3

3 Answers

14
votes

Try:

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

Try

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

}

}