Ask your Symfony questions! Pay money and get answers fast! (more info)

How to sort Ascending/Descending based on query parameter? Symfony

  • SOLVED

I have a criteria like the following:

$c->addAscendingOrderByColumn('COALESCE(' . self::BRAND_NAME. ', '. self::NR_BRAND_NAME .')');

which works fine. But I need to change the order from Ascending to Descending based on the query parameter.

What I do here is:

if ($order == 'D')
$orderclause = 'addDescendingOrderByColum'
else
$orderclause = 'addAscendingOrderByColum';


and then add the criteria as:

$c->{$orderclause}('COALESCE(' . self::BRAND_NAME. ', '. self::NR_BRAND_NAME .')' );

In which case I get the following error.

Fatal error: Call to undefined method Criteria::addDescendingOrderByColum() in /home/marshall/lib/model/CartSunroofLog2Peer.php on line 194

Answers (3)

2010-06-17

Clément JOBEILi answers:

You mispelled addDescendingOrderByColum => addDescendingOrderByColumn

if ($order == 'D')
$orderclause = 'addDescendingOrderByColumn'
else
$orderclause = 'addAscendingOrderByColumn';

2010-06-17

GlobalOrangeLab answers:

1) you misspelled
addDescendingOrderByColum => addDescendingOrderByColumn

2) if ($order == 'D')

$orderclause = 'addDescendingOrderByColumn'

else

$orderclause = 'addAscendingOrderByColumn';

you can use
$c->{$orderclause} ('COALESCE(' . self::BRAND_NAME. ', '. self::NR_BRAND_NAME .')' );
either
$c->$orderclause('COALESCE(' . self::BRAND_NAME. ', '. self::NR_BRAND_NAME .')' );

Hope this helps.

2010-06-17

Arturo Linares answers:

Weird. And do you get an error using this?

$c->addDescendingOrderByColumn(COALESCE(' . self::BRAND_NAME. ', '. self::NR_BRAND_NAME .')');