Tag Archives: propel

Snippet: Symfony & Propel–Queries with SQL functions

This is a super short snippet that I ALWAYS forget how to do! Often I want to build more complex where clauses with Propel Criteria which use SQL functions such as UCASE, LCASE, LEN and the date functions DAY, MONTH and YEAR. This is possible using Propel & Criteria, but how to do it is not immediately obvious.

The snippet below shows how to select objects from the database which were created in a specific month and year. Using Criteria::CUSTOM, it’s possible to specify a column and a comparison to do with that column. This is quite useful for doing things like building archive lists.

$c->add(MyObjPeer::CREATED_AT, ‘MONTH(‘.MyObjPeer::CREATED_AT.’)=’. $month, Criteria::CUSTOM);
$c->addAnd(MyObjPeer::CREATED_AT, ‘YEAR(‘.MyObjPeer::CREATED_AT.’)=’. $year, Criteria::CUSTOM);
A Note on Snippets: When using frameworks such as Symfony it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know. Continue reading

Posted in Symfony | Tagged , , , | View Comments

Using Namespaces in Propel 1.5

Propel 1.5 does not cease to please the pace of development and introduction of new features, just a few weeks ago, Francois Zaninotto(project leader Propel) has published a new opportunity to edit the nested forms using mergeRelation and embedRelation and the other day to use Namespaces in the generation of models.

Propel 1.5 allows the use of Namespaces in files describing your model if you are using in the php version 5.3

Add the use of models is very simple:






A model class:

/ / Use fully qualified name
$ Book = new \ Bookstore \ Book ();
/ / Or use an alias
use Bookstore \ Book;
$ Book = new Book ();
/ / Remember to use the \ namespace for core Propel classes in this case
$ Con = \ Propel:: getConnection ();
$ Book-> save ($ con);
More details can be read in the blog Francois Zaninotto Continue reading

Posted in Symfony | Tagged , , , , , | View Comments
Get Adobe Flash playerPlugin by wpburn.com wordpress themes

DecentMind is Digg proof thanks to caching by WP Super Cache