views:

127

answers:

1

Hello,

on the backend on symfony 1.4 / Doctrine, you have a tool which allows you to filter data according to date, location, age (and many more according to your model)

EXAMPLE

I'm searching a way to do the same (with some customisation such as removing some fields) but in the frontend. I didn't find any documentation on how to do it

Do you have an idea please ?

Thanks

+1  A: 

If you want to do it exactly like it is done on the backend, you can use the admin generator on frontend applications. A more general and customizable way would be to simply create list and filter actions and use Symfony's form filters. Here's a basic example for a model class "Article":

In an actions class:

class articleActions extends sfActions
{
  public function executeList(sfWebRequest $request)
  {
    $this->form = new ArticleFormFilter();
    $this->pager = new new sfDoctrinePager('Article');
  }

  public function executeFilter(sfWebRequest $request)
  {
    $this->form = new ArticleFormFilter();
    $this->form->bind($request[$this->form->getName()]);
    if ($this->form->isValid())
    {
      $this->pager = new new sfDoctrinePager('Article');
      $this->pager->setQuery($this->form->getQuery());
      $this->setTemplate('list');
    }
    //handle invalid form here
  }
}

In view, iterate throw pager like this:

 foreach($pager->getResults() as $article)

Doctrine FormFilter's are fairly similar to Doctrine forms. Get started by configuring the form inside of FormFilter::configure();

jeremy
@jeremy Could you please explain more about the second part of your answer please ? I never use filters. Coud you please list the steps i need to reproduce ? Thanks
Tristan