Symfony Admin Generator Calling Actions with Custom Parameters

The administration module actions can receive custom parameters using the query_string argument in a link_to() helper. For example, to extend the previous _edit_header partial with a link to the comments for the article, write this:

It filters the comments to display only the ones related to $article. Using the query_string argument, you can specify a sorting order and/or a filter to display a custom list view. This can also be useful for custom interactions.

Override index function

public function executeIndex(sfWebRequest $request)
{
// For filter.. This code was missing in symfony documentation.
if ($request->getParameter('filter'))
{
$this->setFilters($request->getParameter('project_filters'));
}

//-----------------

// sorting
if ($request->getParameter('sort'))
{
$this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type')));
}

// pager
if ($request->getParameter('page'))
{
$this->setPage($request->getParameter('page'));
}

$this->pager = $this->getPager();
$this->sort = $this->getSort();
}

Similar Posts

8 Responses to “Symfony Admin Generator Calling Actions with Custom Parameters”

B@D on September 1st, 2009 at 9:08 PM

Wasn’t this a general Technology blog ?

admin on September 1st, 2009 at 9:11 PM

@B@D
When it was, No one bothered to post :D

B@D on September 1st, 2009 at 9:20 PM

It needs Time & Research to Post something Original. ;-)

Faizan on September 1st, 2009 at 9:28 PM

Find me this post anywhere on World Wide Web (www) and I’ll stop blogging :P

It took me whole day just to figure out how to make this thing work.

And If you cant understand what is this Just leave it. People who know symfony know the worth of this code snippet :D

sT*rchi1Ð on September 2nd, 2009 at 11:51 PM

Faizan :

Find me this post anywhere on World Wide Web (www) and I’ll stop blogging :P

It took me whole day just to figure out how to make this thing work.

And If you cant understand what is this Just leave it. People who know symfony know the worth of this code snippet :D

exactly, btw wht is it? :D

B@D on September 4th, 2009 at 3:51 PM

I love symfony.
Thanks! Great help.

Faizan on September 4th, 2009 at 6:07 PM

@sT*rchi1Ð
Thanks you got my point :P and this is not for you.

@B@D
Thanks for appreciation :P btw I know what you mean by this :D

jarod.chiang on December 1st, 2009 at 2:55 PM

My Solution is:
1.
This article has
getNbComments().’ comments’, ‘comment/list’, array(‘query_string’ => ‘filter=filter&filters[article_id]=’.$article->getId())) ?> comments.
2.
add a function called list in apps/MyApp/modules/commnent
==============================================================
class comment extends autoComment {
public function executeList(sfWebRequest $request)
{
if ($request->hasParameter(‘filter’))
{
$this->setFilters($request->getParameter(‘filters’));
}
$this->redirect(‘@comment’);
}
}
================================================================

[refer to]
http://www.symfony-project.org/book/1_2/14-Generators

Leave a Reply