Module query does not order by the requested order.[SOLVED]

edited July 2012 in News & Announcements
Hi,

I have a table called: categories.
The fields in the table are:
id
name
url
published

I am calling the model in a file called: sidemenu.php which builds my side menu, like this:
$cats = fuel_model('categories', array('find' => 'all', 'where' => array('published' => 'yes'), 'name asc')); foreach($cats as $cat): $id = $cat->id; $title = $cat->name; $catUrl = $cat->url; $numOfSubCats = $CI->sub_categories_model->record_count(array('cat_id'=>$id)); $total = $CI->categories_to_members_model->record_count(array('category_id'=>$id)); $label = $title . ' (' . $total . ')'; $nav['members/' . $catUrl] = array('label'=>$label); if($numOfSubCats != 0): $subCats = fuel_model('sub_categories', array('find' => 'all', 'where' => array('cat_id' => $id), 'name asc')); foreach($subCats as $sub): $subCatId = $sub->id; $url = $sub->url; $subName = $sub->name; $subTotal = $CI->categories_to_members_model->record_count(array('category_id'=>$id, 'sub_cat_id'=>$subCatId)); if(empty($subTotal)) $subTotal = 0; $subLabel = $subName . ' (' . $subTotal . ')'; $nav['members/' . $title . '/' . $url] = array('label' => $subLabel, 'parent_id' => 'members/' . $catUrl); endforeach; endif; endforeach;

The results displayed are not ordered by the category name: (For example: Venues/Weddings comes before Hungry or Thirsty?
<ul id="accordion" class="accordion"> <li class="first"><a href="http://localhost/clarenssa/members/accommodation" title="Accommodation (18)">Accommodation (18)</a> <ul> <li class="first"><a href="http://localhost/clarenssa/members/Accommodation/bb" title="B & B (6)">B & B (6)</a></li> <li><a href="http://localhost/clarenssa/members/Accommodation/selfcatering" title="Self-Catering (10)">Self-Catering (10)</a></li> <li class="last"><a href="http://localhost/clarenssa/members/Accommodation/hotel" title="Hotel (1)">Hotel (1)</a></li> </ul> </li> <li><a href="http://localhost/clarenssa/members/healthbeauty" title="Health & Beauty (6)">Health & Beauty (6)</a></li> <li><a href="http://localhost/clarenssa/members/outdoors" title="Outdoors (4)">Outdoors (4)</a></li> <li><a href="http://localhost/clarenssa/members/functions" title="Venues/Weddings (0)">Venues/Weddings (0)</a></li> <li><a href="http://localhost/clarenssa/members/retail" title="Retail (4)">Retail (4)</a></li> <li><a href="http://localhost/clarenssa/members/hungrythirsty" title="Hungry or Thirsty? (7)">Hungry or Thirsty? (7)</a></li> <li class="last"><a href="http://localhost/clarenssa/members/services" title="Services (9)">Services (9)</a></li> </ul>

My categories model:
class Categories_model extends Base_module_model { public $record_class = 'Category'; function __construct() { parent::__construct('categories'); } // cleanup category to members function on_after_delete($where) { $this->delete_related('categories_to_members_model', 'category_id', $where); } // add unique name validation function on_before_validate($values) { if (!empty($values['id'])) { $this->add_validation('name', array(&$this, 'is_editable'), lang('error_val_empty_or_already_exists', lang('form_label_name')), array('name', $values['id'])); } else { $this->add_validation('name', array(&$this, 'is_new'), lang('error_val_empty_or_already_exists', lang('form_label_name')), 'name'); } return $values; } } class Category_model extends Base_module_record { function get_members($subCatId) { $this->_CI->load->model('categories_to_members_model'); if($subCatId != 0) $where = array('category_id' => $this->id, 'sub_cat_id' => $subCatId, 'members.published' => 'yes'); else $where = array('category_id' => $this->id, 'members.published' => 'yes'); $members = $this->_CI->categories_to_members_model->find_all($where); return $members; } }

What am I doing wrong?

Comments

  • edited 3:11AM
    Ok, found the solution:
    Instead of this:
    $cats = fuel_model('categories', array('find' => 'all', 'where' => array('published' => 'yes'), 'name asc'));
    I use this:
    $cats = $CI->categories_model->find_all(array('published' => 'yes'), 'name asc');
  • edited 3:11AM
    You can also use the "order" parameter:
    fuel_model('categories', array('find' => 'all', 'where' => array('published' => 'yes'), 'order' => 'name asc'));
Sign In or Register to comment.