quick symfony tips.


I am learning symfony. Just got some good tips to share with you.
Symfony rocks.🙂

I will update this regularly.

1> How to write OR condition query in symfony.
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(TablePeer::TBL_ID);
$cton1 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton2 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton1->addOr($cton2);
$c->add($cton1);

2> How to get query where first date greater then and less then last date.
$date1 = date('Y-m-d 00:00:00');
$date2 = date('Y-m-d 23:59:59');
$cton1 = $gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date1, Criteria::GREATER_EQUAL);
$cton1->addAnd($gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date2, Criteria::LESS_EQUAL));
$gUser->add($cton1);

3> how to run the update query in symfony.

“update table TableName set TableField1=’1′ where TableField2=$some_value.”

$update = new TableName();
$update->setNew(false);
$update->setTableField1(1);
$update->setTableField2($imageId); // this is primary key of the table. include this line.
$update->save();
?>

technorati tags:
, , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: