Home > ExtJs, Symfony > Symfony and ExtJS Grid Search

Symfony and ExtJS Grid Search

I’ve been working on several projects that have utilized an ExtJS grid using the search plugin, with a Symfony backend.  One of the features of the grid search plugin is that it allows the user to search across several fields (columns) all at once.  Below is a snippet of code I found very useful in my actions when working with the grid search plugin, and symfony.

$column = AdvertisementPeer::translateFieldName(sfInflector::camelize(strtolower($field)), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
if($request->getParameter('query') != ""){
    array_push($crit_array, $c->getNewCriterion($column,"%".$request->getParameter('query')."%",Criteria::LIKE));
}

The code in the case takes a field string (given to us by a POST to the server from the search plugin), maps it to the peer class using [cci_php] sfInflector::camelize()[/cci_php] for the domain object we’re searching on, and then adds a new criteria search for that item to a query.  The work horse of this snippet is the sfInflector class.  Pretty useful class.  That, and it saves you from having to write [cci_php]Peer::COLUMN_NAMES[/cci_php] out all the time.

Categories: ExtJs, Symfony Tags: , ,
  1. August 5th, 2009 at 15:40 | #1

    Or you could just do this
    $column = AdvertisementPeer::translateFieldName($field, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
    ;)

  1. December 24th, 2009 at 11:47 | #1