Jump to content

Order by Silex


unplugged_web

Recommended Posts

I wonder if somebody could help me please, I'm new to Symphony and am working on a site that's been built using Silex.
I want to add an 'order by' option to database results. I've got a page that has lots of information and I want the user to be able to choose the order it's sorted by, for example if they click on name it sorts the results via name, if they click email address is sorts by that etc.
I've spent a few weeks trying to get this to work but haven't got anywhere so would be grateful for any help. In the query file (php) there's lots of 'filterBy' functions. filterByEmail, filterByName for example, but I don't know if this is right or if it is how to call it from within the twig file.
Thanks in advance for any help.
Link to comment
Share on other sites

Most of that work is done by your database query, PHP is how you get access to the results of your query. Please post your query.

Link to comment
Share on other sites

Only one query per database table is made but there's a 'filterBy' function for every field. For example here's the one for names and email addresses.

public function filterByName($name = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($name)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[%*]/', $name)) {
                $name = str_replace('*', '%', $name);
                $comparison = Criteria::LIKE;
            }
        }
 
        return $this->addUsingAlias(CustomerContactTableMap::NAME, $name, $comparison);
    }

and

public function filterByEmail($email = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($email)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[%*]/', $email)) {
                $email = str_replace('*', '%', $email);
                $comparison = Criteria::LIKE;
            }
        }
 
        return $this->addUsingAlias(CustomerContactTableMap::EMAIL, $email, $comparison);
    }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...