$query = Model_Article::find()->where('category_id', 1)->order_by('date' => 'desc');
$data['results'] = Model_Blog::find()->order_by(array('blog_date' => 'desc'));
$data['results'] = Model_Blog::find()->order_by('blog_date', 'desc');
Fuel\Core\Fuel_Exception [ Error ]: Object class was not whitelisted in security.whitelisted_classes and could not be converted to string. COREPATH/classes/security.php @ line 180
$data['results'] = Model_Blog::find('all', array( 'order_by' => array('blog_date' => 'desc') ));
$data['results'] = Model_Blog::find('all', array( 'order_by' => array('blog_date' => 'desc') ));Query run
SELECT `t0`.`id` AS `t0_c0`, `t0`.`title` AS `t0_c1`, `t0`.`post` AS `t0_c2`, `t0`.`blog_date` AS `t0_c3` FROM `blogs` AS `t0` ORDER BY `t0`.`blog_date` DESC Possible keys: · Key Used: · Type: ALL · Rows: 2 · Speed: 0.000 msNo query (0 Queries) are run using:
$data['results'] = Model_Blog::find()->order_by(array('blog_date' => 'desc'));Here is my Model_Blog
class Model_Blog extends Orm\Model { protected static $_properties = array('id', 'title', 'post', 'blog_date'); protected static $_has_many = array('comments'); }And here is my Model_Comments
class Model_Comments extends Orm\Model { protected static $_properties = array('id', 'blog_id', 'author', 'comment', 'comment_date'); protected static $_belongs_to = array('blog'); }And my database structure
-- -- Table structure for table `blogs` -- CREATE TABLE IF NOT EXISTS `blogs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `post` text NOT NULL, `blog_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -------------------------------------------------------- -- -- Table structure for table `comments` -- CREATE TABLE IF NOT EXISTS `comments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `blog_id` int(11) NOT NULL, `author` varchar(255) NOT NULL, `comment` text NOT NULL, `comment_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
$data['results'] = Model_Blog::find()->order_by(array('blog_date' => 'desc'));This won't do a query because you don't tell it to. You create the query using find(), tell it to order desc by blog_date. But you never tell it to execute.
// find all for your query $data['results'] = Model_Blog::find()->order_by(array('blog_date' => 'desc'))->get(); // get only the first result (or, as you're using "desc" ordering, actually the last) $data['results'] = Model_Blog::find()->order_by(array('blog_date' => 'desc'))->get_one();
$data['results'] = Model_Blog::find()->order_by('blog_date', 'desc')->get();
It looks like you're new here. If you want to get involved, click one of these buttons!