Skip to Content

Configuring Symfony generator sort filter

Symfony is a great open source PHP framework that we have been using a lot lately. However, the documentation can be a bit sketchy sometimes so here is how to configure the sort option in the Symfony admin generator.

The sort option allows you to set a default sort on an Admin generator list. You can view the Symfony documentation for it here:

    sort:   created_at
    # Alternative syntax, to specify a sort order
    sort:   [created_at, desc]

Now, the sort option allows only ONE field to be used for the default sort order of the list. You can't set more than one field as the sort order. Then for each field you can specify either 'desc' which in this example would set the list to descend by the created_at field, or 'asc' which allows the opposite.

One other thing to remember is that the sort order is stored within the session once you visit the list page. So if you are changing the sort order and refresh the page you will find that nothing happens. Clearing the Symfony cache won't help and you must either delete the Symfony cookie or reload the browser to see any new sort option changes that you make.