本文整理汇总了PHP中Posts::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::orderBy方法的具体用法?PHP Posts::orderBy怎么用?PHP Posts::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Posts
的用法示例。
在下文中一共展示了Posts::orderBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
<?php
$app->get('/(:page)', function ($page = 1) use($app, $settings) {
$p = Posts::count();
$pages = ceil($p / $settings->post_per_page);
if ($page > $pages) {
$app->pass();
}
$posts = Posts::orderBy('creation', 'desc')->skip($settings->post_per_page * ($page - 1))->take($settings->post_per_page)->get();
$arr = array();
//Posts
foreach ($posts as $post) {
if ($post['active'] == 'true') {
$post['author'] = Users::get_author($post['user_id']);
$post['date'] = date('d-m-Y H:i', $post['creation']);
$post['url'] = $app->request->getUrl() . $app->request->getPath() . 'post/' . $post['id'];
if ($settings->truncate == 'true') {
$text = truncate_to_n_words($post['text'], 70, $post['url']);
$post['text'] = $app->markdown->parse($text);
} else {
$post['text'] = $app->markdown->parse($post['text']);
}
$post['count'] = Posts::find($post['id'])->comments->count();
$arr[] = $post;
}
}
$app->render('posts.html', array('posts' => $arr, 'pages' => $pages, 'page' => $page));
})->conditions(array('page' => '\\d+'));
示例2: index
/**
* Display a listing of postst_topic
*
* @return Response
*/
public function index()
{
$posts = Posts::orderBy('created_at', 'DESC')->get();
return View::make('posts.index', compact('posts'));
}
示例3: array
$user = Users::whereRaw('username = ? AND password = ?', array($username, $password))->get();
if ($user->count() != 0) {
$_SESSION['user'] = $username;
$app->redirect($settings->base_url . '/admin');
} else {
$app->flash('error', 1);
$app->redirect($settings->base_url . '/admin/login');
}
});
$app->get('/logout/', $authenticate($app, $settings), function () use($app, $settings) {
unset($_SESSION['user']);
$app->view()->setData('user', null);
$app->redirect($settings->base_url);
});
$app->get('/', $authenticate($app, $settings), function () use($app) {
$posts = Posts::orderBy('creation', 'desc')->get();
$arr = array();
foreach ($posts as $post) {
$post['author'] = Users::get_author($post['user_id']);
$post['date'] = date('d-m-Y H:i', $post['creation']);
$post['url'] = $app->request->getUrl() . $app->request->getPath() . 'post/' . $post['id'];
$arr[] = $post;
}
$app->render('a_posts.html', array('posts' => $arr));
});
$app->get('/posts/new/', $authenticate($app, $settings), function () use($app) {
$flash = $app->view()->getData('flash');
$error = isset($flash['error']) ? $flash['error'] : '';
$app->render('a_post_new.html', array('error' => $error));
});
$app->post('/posts/new', $authenticate($app, $settings), function () use($app, $settings) {