Symfony - Doctrine RUD
Thursday, May 24, 2012
Doctrine RUD
READ
$row = Doctrine_Query::create()
->select('count(t.id) as cnt')
->from('Table t')
->where('t.field = ?', 1)
->addWhere('t.field2 = ?', 'blabla')
->fetchArray();
echo $row['0']['cnt'];
pager
$query = Doctrine_Query::create()->from('Table a');
$pager = new sfDoctrinePager('Table', self::PER_PAGE);
$pager->setQuery($query);
$pager->setPage($page);
$pager->init();
return $pager
public function save(Doctrine_Connection $conn = null)
{
if ($this->isNew()) {
$this->setUserId(sfContext::getInstance()->getUser()->getId());
$this->setCreatedAt(date('Y-m-d H:i:s'));
}
return parent::save($conn);
}
UPDATE
Doctrine_Query::create()
->update('Table a')
->set('a.field', 1)
->where('a.id = ?', 1)
->execute();
DELETE
Doctrine_Query::create()
->delete()
->from('Table a')
->where('a.id = ?', 1)
->execute();
0 comments:
Post a Comment