$data['articles'] = Model_Article::find('all', array('order_by' => array('created_at' => 'desc')));
$location = Model_Location::find('first', array( 'related' => array( 'items' => array( 'order_by' => array('name' => 'asc') ), ), ));
$data['articles'] = Model_Article::find()->order_by('created_at', 'desc')->get();
Jelmer Schreuder wrote on Sunday 26th of February 2012:Could you try echo Model_Article::find()->order_by('created_at', 'desc')->get_query(); and show me the resulting query.
Jelmer Schreuder wrote on Sunday 26th of February 2012:Aren't you doing something of your own after this and before the foreach that may change the order? The ORM doesn't do any reordering, it just works through the returned data in the order that it's been given.
public function action_index() { $data['articles'] = Model_Article::find()->order_by('created_at', 'desc')->get(); $this->template->content = View::forge('admin/articles/index', $data); }
<?php if ($articles): ?> <table id="table-articles" class="striped"> <thead> <tr> <th class="header">#</th> <th class="yellow header">Title</th> <th class="orange header">Category</th> <th class="blue header">Status</th> <th class="green header">Created at</th> <th class="green header">Published at</th> <th class="header">Actions</th> </tr> </thead> <tbody> <?php foreach ($articles as $article): ?> <tr> <td><?php echo $article->id; ?></td> <td><?php echo $article->title; ?></td> <td><span class="<?php echo $article->category->fontclass ?>"><?php echo $article->category->name; ?></span></td> <td> <?php echo $article->status->name; ?> </td> <td><?php echo date('d.m.Y', $article->created_at) ?></td> <td><?php echo date('d.m.Y', $article->published_at) ?></td> <td nowrap> <?php echo Html::anchor('articles/preview/'.$article->id, 'View', array('target'=>'_blank')); ?> | <?php echo Html::anchor('admin/articles/edit/'.$article->id, 'Edit'); ?> | <?php echo Html::anchor('admin/articles/delete/'.$article->id, 'Delete', array('onclick' => "return confirm('Are you sure?')")); ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> <p>No articles.</p> <?php endif; ?>
echo Model_Location::find('first', array( 'related' => array( 'items' => array( 'order_by' => array('name' => 'asc') ), ), ))->get_query()
It looks like you're new here. If you want to get involved, click one of these buttons!