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

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
How to sort Ascending/Descending based on query parameter?

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

This question has been answered.

marshall | 06/17/10 at 11:39am Edit


(3) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    06/17/10
    12:41pm
    Clément JOBEILi says:

    You mispelled addDescendingOrderByColum => addDescendingOrderByColumn


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

    Previous versions of this answer: 06/17/10 at 12:12pm | 06/17/10 at 12:12pm

  • avatar
    Last edited:
    06/17/10
    11:44am
    Arturo Linares says:

    Weird. And do you get an error using this?

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


  • avatar
    Last edited:
    06/17/10
    12:41pm
    GlobalOrangeLab says:

    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.

    Previous versions of this answer: 06/17/10 at 12:06pm

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.