本文整理汇总了PHP中Post::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::count方法的具体用法?PHP Post::count怎么用?PHP Post::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: home
/**
* Display the list of paginated Posts (draft and published)
*/
function home()
{
Doo::loadHelper('DooPager');
Doo::loadModel('Post');
$p = new Post();
//if default, no sorting defined by user, show this as pager link
if ($this->sortField == 'createtime' && $this->orderType == 'desc') {
$pager = new DooPager(Doo::conf()->APP_URL . 'admin/post/page', $p->count(), 6, 10);
} else {
$pager = new DooPager(Doo::conf()->APP_URL . "admin/post/sort/{$this->sortField}/{$this->orderType}/page", $p->count(), 6, 10);
}
if (isset($this->params['pindex'])) {
$pager->paginate(intval($this->params['pindex']));
} else {
$pager->paginate(1);
}
$data['rootUrl'] = Doo::conf()->APP_URL;
$data['pager'] = $pager->output;
//Order by ASC or DESC
if ($this->orderType == 'desc') {
$data['posts'] = $p->limit($pager->limit, null, $this->sortField, array('select' => 'id,createtime,status,title,totalcomment'));
$data['order'] = 'asc';
} else {
$data['posts'] = $p->limit($pager->limit, $this->sortField, null, array('select' => 'id,createtime,status,title,totalcomment'));
$data['order'] = 'desc';
}
$this->render('admin', $data);
}
示例2: actionShow
/**
* 查看专题
*/
public function actionShow($name)
{
$specialModel = Special::model()->find('title_alias=:titleAlias', array('titleAlias' => CHtml::encode(strip_tags($name))));
if (false == $specialModel) {
throw new CHttpException(404, '专题不存在');
}
//更新浏览次数
$specialModel->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $specialModel->id));
$specialPostModel = new Post();
$criteria = new CDbCriteria();
$criteria->addCondition('t.status_is=:status AND special_id=:specialId');
$criteria->params = array('status' => 'Y', 'specialId' => $specialModel->id);
$criteria->order = 't.id DESC';
$bagecmsSpecialCount = $specialPostModel->count($criteria);
$postPage = new CPagination($bagecmsSpecialCount);
$postPage->pageSize = 10;
$postPageParams = XUtils::buildCondition($_GET, array());
$postPageParams['#'] = 'list';
$postPage->params = is_array($postPageParams) ? $postPageParams : array();
$criteria->limit = $postPage->pageSize;
$criteria->offset = $postPage->currentPage * $postPage->pageSize;
$specialPostList = $specialPostModel->findAll($criteria);
$this->_seoTitle = empty($specialModel->seo_title) ? $specialModel->title . ' - ' . $this->_conf['site_name'] : $specialModel->seo_title;
$tpl = empty($specialModel->tpl) ? 'show' : $specialModel->tpl;
$data = array('specialShow' => $specialModel, 'specialPostList' => $specialPostList, 'bagecmsPagebar' => $postPage);
$this->render($tpl, $data);
}
示例3: testDestroy
public function testDestroy()
{
$post = Factory::create('Post');
$this->action('DELETE', 'Admin\\PostsController@destroy', $post->slug);
$this->assertRedirectedToRoute('admin.posts.index');
$this->assertEquals(0, Post::count());
}
示例4: testAggregate
public function testAggregate()
{
$count = Post::count();
$debug = last(DB::getQueryLog());
$this->assertEquals(3, $count);
$this->assertEquals('select count(*) as aggregate from "posts" where "published" = ? and "status" = ?', $debug['query']);
}
示例5: actionIndex
/**
* 首页
*
*/
public function actionIndex()
{
$model = new Post();
$criteria = new CDbCriteria();
$condition = "1=1";
$title = trim($this->_request->getParam('title'));
$catalogId = intval($this->_request->getParam('catalogId'));
$title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
$catalogId && ($condition .= ' AND catalog_id= ' . $catalogId);
$criteria->condition = $condition;
$criteria->order = 't.id DESC';
$criteria->with = array('catalog');
$count = $model->count($criteria);
$pages = new CPagination($count);
$pages->pageSize = 10;
//根据title,catelogId,titleAlias查询
$pageParams = $this->buildCondition($_GET, array('title', 'catalogId'));
$pages->params = is_array($pageParams) ? $pageParams : array();
$criteria->limit = $pages->pageSize;
$criteria->offset = $pages->currentPage * $pages->pageSize;
$result = $model->findAll($criteria);
//推荐位
$recom_list = RecommendPosition::model()->findAll('type=:type', array(':type' => $this->_type), array('order' => 'id'));
$this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'recom_list' => $recom_list));
}
示例6: actionIndex
/**
* 首页
*
*/
public function actionIndex()
{
parent::_acl();
$model = new Post();
$criteria = new CDbCriteria();
$condition = '1';
$title = trim($this->_gets->getParam('title'));
$titleAlias = trim($this->_gets->getParam('titleAlias'));
$catalogId = intval($this->_gets->getParam('catalogId'));
$title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
$titleAlias && ($condition .= ' AND title_alias LIKE \'%' . $titleAlias . '%\'');
$catalogId && ($condition .= ' AND catalog_id= ' . $catalogId);
$criteria->condition = $condition;
$criteria->order = 't.id DESC';
$criteria->with = array('catalog');
$count = $model->count($criteria);
$pages = new CPagination($count);
$pages->pageSize = 13;
$pageParams = XUtils::buildCondition($_GET, array('title', 'catalogId', 'titleAlias'));
$pages->params = is_array($pageParams) ? $pageParams : array();
$criteria->limit = $pages->pageSize;
$criteria->offset = $pages->currentPage * $pages->pageSize;
$result = $model->findAll($criteria);
$this->render('index', array('datalist' => $result, 'pagebar' => $pages));
}
示例7: _catalogList
/**
* 获取栏目内容数据
*
* @param array $params
* @return array 数组
*/
protected function _catalogList($params = array())
{
$postModel = new Post();
$postCriteria = new CDbCriteria();
$condition = '1';
if ($params['catalog']) {
$condition .= ' AND t.catalog_id=:catalogId';
$criteriaParams[':catalogId'] = intval($params['catalog']);
}
if ($params['keyword']) {
$condition .= ' AND t.title=:title';
$criteriaParams[':title'] = CHtml::encode(strip_tags($params['keyword']));
}
$condition .= " AND t.status_is='Y'";
$postCriteria->condition = $condition;
$postCriteria->params = $criteriaParams;
$postCriteria->order = 't.id DESC';
$postCriteria->with = 'catalog';
$count = $postModel->count($postCriteria);
$postPages = new CPagination($count);
$postPages->pageSize = $params['pageSize'] > 0 ? $params['pageSize'] : 20;
$pageParams = XUtils::buildCondition($_GET, array('catalog', 'keyword'));
$postPages->params = is_array($pageParams) ? $pageParams : array();
$postCriteria->limit = $postPages->pageSize;
$postCriteria->offset = $postPages->currentPage * $postPages->pageSize;
$bagecmsDataList = $postModel->findAll($postCriteria);
$catalogArr = Catalog::item($params['catalog'], $this->_catalog);
if ($catalogArr) {
$this->_seoTitle = empty($catalogArr['catalog_name']) ? $this->_seoTitle : $catalogArr['catalog_name'];
$bagecmsCatalogData = $catalogArr;
$this->_seoKeywords = empty($catalogArr['seo_keywords']) ? $this->_seoKeywords : $catalogArr['seo_keywords'];
$this->_seoDescription = empty($catalogArr['seo_description']) ? $this->_seoDescription : $catalogArr['seo_description'];
}
return array('bagecmsDataList' => $bagecmsDataList, 'bagecmsPagebar' => $postPages, 'bagecmsCatalogData' => $bagecmsCatalogData);
}
示例8: showWelcome
public function showWelcome()
{
//echo "Coming Soon";
try {
DB::connection()->getDatabaseName();
//Session::set('locale' , 'es');
$post = Post::get();
$cats = Category::orderBy('order_type')->get();
$noti_post = Post::orderBy(DB::raw('RAND()'))->where('is_approved', 1)->first();
$post_test = Post::count();
// i++ page count
counter('home');
return View::make('index')->with('posts', $post)->with('noti_post', $noti_post)->with('cats', $cats)->with('post_test', $post_test);
} catch (Exception $e) {
return Redirect::route('install');
}
}
示例9: run
public function run()
{
$model = new Post();
//条件
$criteria = new CDbCriteria();
$title = trim(Yii::app()->request->getParam('title'));
$catalogId = intval(Yii::app()->request->getParam('catalogId'));
$criteria->addColumnCondition(array('type' => $this->controller->_type));
$title && $criteria->addSearchCondition('title', $title);
$catalogId && $criteria->addColumnCondition(array('catalog_id' => $catalogId));
$criteria->order = 't.id DESC';
$criteria->with = array('catalog');
$count = $model->count($criteria);
//分页
$pages = new CPagination($count);
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$result = $model->findAll($criteria);
$this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
}
示例10: topic
/**
* Список сообщений
*/
public function topic($id)
{
if (!($topic = Topic::find_by_id($id))) {
App::abort('default', 'Данной темы не существует!');
}
if (User::check()) {
$bookmark = Bookmark::find_by_topic_id_and_user_id($id, User::get('id'));
if ($bookmark && $topic->postCount() > $bookmark->posts) {
$bookmark->posts = $topic->postCount();
$bookmark->save();
}
}
$total = Post::count(['conditions' => ['topic_id = ?', $id]]);
$page = App::paginate(Setting::get('posts_per_page'), $total);
$posts = Post::all(['conditions' => ['topic_id = ?', $id], 'offset' => $page['offset'], 'limit' => $page['limit'], 'order' => 'created_at', 'include' => ['user']]);
$crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
if ($topic->forum()->parent_id) {
$crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->parent_id => $topic->forum()->parent()->title, '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
}
App::view('forums.topic', compact('topic', 'posts', 'page', 'crumbs'));
}
示例11: home
function home()
{
Doo::loadHelper('DooPager');
Doo::loadModel('Post');
$p = new Post();
$p->status = 1;
//published post only
$pager = new DooPager(Doo::conf()->APP_URL . 'page', $p->count(), 4, 10);
if (isset($this->params['pindex'])) {
$pager->paginate(intval($this->params['pindex']));
} else {
$pager->paginate(1);
}
//limit post and order by create time descendingly, get only Posts
//$this->data['posts'] = $p->limit($pager->limit, null, 'createtime');
//limit post and order by create time descendingly with post's tags
$this->data['posts'] = $p->relateTag(array('limit' => $pager->limit, 'desc' => 'post.createtime', 'asc' => 'tag.name', 'match' => false));
$this->data['pager'] = $pager->output;
$this->data['rootUrl'] = Doo::conf()->APP_URL;
//prepare sidebar data, tags and archive list
$this->prepareSidebar();
$this->render('index', $this->data);
}
示例12: actionIndex
/**
* 首页
*/
public function actionIndex()
{
$keyword = CHtml::encode(strip_tags(trim($this->_gets->getParam('keyword'))));
$postModel = new Post();
$postCriteria = new CDbCriteria();
if ($keyword) {
$postCriteria->addSearchCondition('t.title', $keyword);
}
$postCriteria->addCondition('t.status_is=:status');
$postCriteria->params[':status'] = 'Y';
$postCriteria->with = 'catalog';
$postCriteria->order = 't.id DESC';
$bagecmsQuestionCount = $postModel->count($postCriteria);
$postPages = new CPagination($bagecmsQuestionCount);
$postPages->pageSize = 15;
$postPageParams = XUtils::buildCondition($_GET, array('keyword'));
$postPageParams['#'] = 'list';
$postPages->params = is_array($postPageParams) ? $postPageParams : array();
$postCriteria->limit = $postPages->pageSize;
$postCriteria->offset = $postPages->currentPage * $postPages->pageSize;
$postList = $postModel->findAll($postCriteria);
$this->render('index', array('bagecmsDataList' => $postList, 'bagecmsPagebar' => $postPages));
}
示例13: posts_list
/**
* Posts list
*
* @param Request $request
* @param $opts
* @return mixed
*/
public function posts_list(Request $request, $opts)
{
$title = $this->lang->translate('post.list');
// Delete post
if ($request->get('delete')) {
$post = \Post::find_by_id(intval($request->get('delete')));
if ($post && $post->delete()) {
$this->view->assign('message', $this->lang->translate('form.deleted'));
}
}
// Publish post
if ($request->get('accept')) {
$post = \Post::find_by_id(intval($request->get('accept')));
if ($post) {
$post->moderate = '0';
$post->created_at = time();
if ($post->save()) {
$this->view->assign('message', $this->lang->translate('post.published'));
}
// Export to social
$post->export();
// Pinging sitemap
NCService::load('SocialMedia.Ping');
} else {
$this->view->assign('message', $this->lang->translate('post.error_publish'));
}
}
// Filter
$filter['order'] = 'id DESC';
if ($request->order) {
$filter['order'] = $request->order;
}
$conditions = [];
$values = [];
// By Category
if ($request->get('category')) {
$category = \PostCategory::find($request->get('category'));
if ($category) {
$conditions[] = 'category_id = ?';
$values[] = $category->id;
}
}
// By Author
if ($request->get('author')) {
$author = \User::find($request->get('author'));
if ($author) {
$conditions[] = 'author_id = ?';
$values[] = $author->id;
}
}
// Premoderate
$conditions[] = 'moderate = ?';
if ($opts->get('mod')) {
$title = $this->lang->translate('post.onmoderation');
$values[] = '1';
} else {
$values[] = '0';
}
if ($conditions) {
$filter['conditions'] = array_merge([implode(' AND ', $conditions)], $values);
}
/** @var Listing $paginator */
$paginator = NCService::load('Paginator.Listing', [$request->page, \Post::count($filter)]);
$filter = array_merge($filter, $paginator->limit());
// Filter users
$posts = \Post::all($filter);
// Mass managing
// Accept all visible
if ($request->get('accept') == 'all') {
foreach ($posts as $item) {
$item->moderate = '0';
$item->save();
// Export to social
Module::export($item, $this->view);
}
// Pinging sitemap
NCService::load('SocialMedia.Ping');
return static::redirect_response($request->getPathInfo());
}
// Sent to moderate all visible
if ($request->get('moderate') == 'all') {
foreach ($posts as $item) {
$item->moderate = '1';
$item->save();
}
return static::redirect_response($request->getPathInfo());
}
// Delete all visible
if ($request->get('delete') == 'all') {
foreach ($posts as $item) {
$item->delete();
}
return static::redirect_response($request->getPathInfo());
//.........这里部分代码省略.........
示例14: function
<?php
Route::collection(array('before' => 'auth,csrf'), function () {
/*
List all posts and paginate through them
*/
Route::get(array('admin/posts', 'admin/posts/(:num)'), function ($page = 1) {
$perpage = Post::perPage();
$total = Post::count();
$posts = Post::sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
$url = Uri::to('admin/posts');
$pagination = new Paginator($posts, $total, $page, $perpage, $url);
$vars['messages'] = Notify::read();
$vars['posts'] = $pagination;
$vars['categories'] = Category::sort('title')->get();
$vars['status'] = 'all';
return View::create('posts/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
});
/*
List posts by category and paginate through them
*/
Route::get(array('admin/posts/category/(:any)', 'admin/posts/category/(:any)/(:num)'), function ($slug, $page = 1) {
if (!($category = Category::slug($slug))) {
return Response::error(404);
}
$query = Post::where('category', '=', $category->id);
$perpage = Post::perPage();
$total = $query->count();
$posts = $query->sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
$url = Uri::to('admin/posts/category/' . $category->slug);
$pagination = new Paginator($posts, $total, $page, $perpage, $url);
示例15: required_params
<?php
required_params('post');
if (User::is('<=20') && Post::count(array('conditions' => array("user_id = ? AND created_at > ? ", User::$current->id, gmd_math('sub', '1D')))) >= CONFIG::member_post_limit) {
respond_to_error("Daily limit exceeded", "#error", array('status' => 421));
}
auto_set_params(array('md5'));
$status = User::is('>=30') ? 'active' : 'pending';
Request::$params->post = array_merge(Request::$params->post, array('updater_user_id' => User::$current->id, 'updater_ip_addr' => Request::$remote_ip, 'user_id' => User::$current->id, 'ip_addr' => Request::$remote_ip, 'status' => $status, 'tempfile_path' => $_FILES['post']['tmp_name']['file'], 'tempfile_name' => $_FILES['post']['name']['file'], 'is_upload' => true));
$post = Post::create(Request::$params->post);
if ($post->record_errors->blank()) {
if (Request::$params->md5 && $post->md5 != strtolower(Request::$params->md5)) {
$post->destroy();
respond_to_error("MD5 mismatch", '#error', array('status' => 420));
} else {
$api_data = array('post_id' => $post->id, 'location' => url_for('post#show', array('id' => $post->id)));
if (CONFIG::dupe_check_on_upload && $post->is_image() && empty($post->parent_id)) {
// if (Request::$format == "xml" || Request::$format == "json") {
// $options = array('services' => SimilarImages::get_services('local'), 'type' => 'post', 'source' => $post);
// $res = SimilarImages::similar_images($options);
// if (!empty($res['posts'])) {
// $post->tags .= " possible_duplicate";
// $post->save();
// $api_data['has_similar_hits'] = true;
// }
// }
$api_data['similar_location'] = url_for('post#similar', array('id' => $post->id, 'initial' => 1));
respond_to_success("Post uploaded", array('#similar', array('id' => $post->id, 'initial' => 1)), array('api' => $api_data));
} else {
respond_to_success("Post uploaded", array('#show', array('id' => $post->id, 'tag_title' => $post->tag_title())), array('api' => $api_data));
}