Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I guess your using propel.</p> <p>Its absolutetly possible to do this, but if these table are not related to anything that could result in some messy code when saving. But if you absolutely need to search in those tables, my approach would be to create an action like:</p> <pre><code>public function executeAutocomplete(sfWebRequest $request) { $q = $request-&gt;getParameter('q');//The value to be searched $limit = $request-&gt;getParameter('limit');//Not completly necessary but recommendable if(count($q) == 0) { return sfView::NONE;//With no input, no search } $results = array( 'article' =&gt; array(), 'photo' =&gt; array(), 'video' =&gt; array()); $article_search = ArticlePeer::search($q,$limit); $photo_search = PhotoPeer::search($q,$limit); $video_search = VideoPeer::search($q,$limit); $this-&gt;process_search($results,$article_search,$photo_search,$video_search); //Process those three arrays to fit your need return $this-&gt;renderText(json_encode($result)); } </code></pre> <p>Now, the search function on the Peer classes could look like this:</p> <p>ArticlePeer>></p> <pre><code>public static function search($q,$limit = null) { $c = new Criteria(); $c-&gt;add(self::NAME,'%'.$q.'%',Criteria::LIKE); if(!is_null($limit)) { $c-&gt;addLimit($limit); } return self::doSelect($c); } </code></pre> <p>Finally as for the widget, i have used and adapted sfWidgetJQueryAutocomplete and it work pretty good so you should check it out.</p> <p>EDIT: The short way to an embbed search field si creating sfForm wit the jQuery widget i mentioned before and leave configuration and js to the widget. You'll have to find a way to handle search resutls. Well i hope this helped you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload