how to order by with fuel_model

edited March 2018 in Modules

I can't understand from the user guide how to order by a specific field with this:
$cheeses = fuel_model('cheeses')

I tried:
$cheeses = fuel_model('cheeses', array('order' => array('cheese_name' =>'asc')));
and this:
$cheeses = fuel_model('cheeses', ['order' => array('cheese_name' =>'asc')]);

I get this error:
Message: explode() expects parameter 2 to be string, array given

I tried this:
$cheeses = fuel_model('cheeses', '', ['order' => array('cheese_name' =>'asc')]);

No ordering is happening

Filename: database/DB_query_builder.php

Can you please help?


  • edited 12:50AM
    Try something like this: $cheeses = fuel_model('cheeses', array('find' => 'all', 'where' => array('post_date <' => date('Y-m-d H:i:s')), 'order' => 'post_date asc'));
  • edited 12:50AM
    Thank you Dernerserft, works perfectly.
Sign In or Register to comment.