當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Banner::count方法代碼示例

本文整理匯總了PHP中Banner::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Banner::count方法的具體用法?PHP Banner::count怎麽用?PHP Banner::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Banner的用法示例。


在下文中一共展示了Banner::count方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: listBanner

 public function listBanner()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $start = Input::has('start') ? (int) Input::get('start') : 0;
     $length = Input::has('length') ? Input::get('length') : 10;
     $search = Input::has('search') ? Input::get('search') : [];
     $banners = Banner::select('id', 'name', 'order_no', 'image', 'active');
     if (!empty($search)) {
         foreach ($search as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             if ($key == 'active') {
                 if ($value == 'yes') {
                     $value = 1;
                 } else {
                     $value = 0;
                 }
                 $banners->where($key, $value);
             } else {
                 $value = ltrim(rtrim($value));
                 $banners->where($key, 'like', '%' . $value . '%');
             }
         }
     }
     $order = Input::has('order') ? Input::get('order') : [];
     if (!empty($order)) {
         $columns = Input::has('columns') ? Input::get('columns') : [];
         foreach ($order as $value) {
             $column = $value['column'];
             if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                 continue;
             }
             $banners->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
         }
     }
     $count = $banners->count();
     if ($length > 0) {
         $banners = $banners->skip($start)->take($length);
     }
     $arrBanners = $banners->get()->toArray();
     $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Banner::count(), 'recordsFiltered' => $count, 'data' => []];
     if (!empty($arrBanners)) {
         foreach ($arrBanners as $banner) {
             $arrReturn['data'][] = array(++$start, $banner['id'], $banner['name'], $banner['image'], $banner['order_no'], $banner['active']);
         }
     }
     $response = Response::json($arrReturn);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
開發者ID:nguyendaivu,項目名稱:imagestock,代碼行數:53,代碼來源:BannersController.php

示例2: sort

 public function sort($id, $sort)
 {
     if (!in_array($sort, array('up', 'down'))) {
         return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序失敗!'));
     }
     $total = Banner::count();
     switch ($sort) {
         case 'up':
             $sort = $this->banner->sort;
             $this->banner->sort = $this->banner->sort + 1 >= $total ? 0 : $this->banner->sort + 1;
             break;
         case 'down':
             $sort = $this->banner->sort;
             $this->banner->sort = $this->banner->sort - 1 < 0 ? $total - 1 : $this->banner->sort - 1;
             break;
     }
     Banner::addConditions($conditions, 'sort = ?', $this->banner->sort);
     $banner = $this->banner;
     $update = Banner::transaction(function () use($conditions, $banner, $sort) {
         if (($next = Banner::find('one', array('conditions' => $conditions))) && (($next->sort = $sort) || true)) {
             if (!$next->save()) {
                 return false;
             }
         }
         if (!$banner->save()) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序失敗!', 'posts' => $posts));
     }
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序成功!'));
 }
開發者ID:comdan66,項目名稱:zeusdesign,代碼行數:34,代碼來源:banners.php

示例3: actionIndex

 /**
  * 首頁
  *
  */
 public function actionIndex()
 {
     parent::_acl('banner_index');
     $model = new Banner();
     $criteria = new CDbCriteria();
     $criteria->order = 'id DESC';
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 5;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages));
 }
開發者ID:zywh,項目名稱:maplecity,代碼行數:18,代碼來源:BannerController.php


注:本文中的Banner::count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。