本文整理汇总了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;
}
示例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' => '排序成功!'));
}
示例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));
}