Example #1
0
 /**
  * Lists all Link models.
  * @return mixed
  */
 public function actionIndex()
 {
     $link = new Link();
     $query = $link->find();
     $query->where('`status` = :status', [':status' => \common\base\Status::NORMAL]);
     $request = Yii::$app->getRequest()->get();
     if (!empty($request['keyWord'])) {
         $query->andWhere('`title` like :title', [':title' => '%' . $request['keyWord'] . '%']);
     }
     $total = $query->count();
     $pageSize = 10;
     $pager = new \common\base\Page();
     $pager->pageName = 'page';
     $pageBarNum = 5;
     $pages = $pager->show($total, $pageSize, $pageBarNum);
     $page = isset($request['page']) ? $request['page'] : 1;
     $offset = $pageSize * ($page - 1);
     if ($offset >= $total) {
         $offset = $total;
     }
     $query->orderBy(" `id` desc");
     $query->offset($offset);
     $query->limit($pageSize);
     $list = $query->asArray()->all();
     return $this->render('index', ['list' => $list, 'pages' => $pages, 'total' => $total]);
 }
Example #2
0
 /**
  * Lists all Diary models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Diary();
     $query = $model::find();
     $query->where(' `status` != :status', [':status' => \common\base\Status::DELETE]);
     $data = $this->diaryType();
     $types = $model->findBySql("select id,type,count(1) as num from diary group by type")->asArray()->all();
     foreach ($types as $typeVal) {
         $type_data[$typeVal['type']] = $typeVal['num'];
         $type_data[$typeVal['type']] = $typeVal['num'];
     }
     $param = [];
     foreach ($data as $key => $val) {
         $param[$key]['id'] = $key;
         $param[$key]['name'] = $val;
         $param[$key]['num'] = isset($type_data[$key]) ? $type_data[$key] : 0;
     }
     $request = Yii::$app->getRequest()->get();
     $type = '';
     if (!empty($request['type'])) {
         $type = $request['type'];
         $query->andWhere(" `type` = :type", [':type' => intval($type)]);
     }
     if (!empty($request['keyWork'])) {
         $query->andWhere(" `title` like :title", [':title' => '%' . $_GET['keyWork'] . '%']);
     }
     $total = $query->count();
     $pageSize = 10;
     $pager = new \common\base\Page();
     $pager->pageName = 'page';
     $pageBarNum = 5;
     $pages = $pager->show($total, $pageSize, $pageBarNum);
     $page = isset($request['page']) ? $request['page'] : 1;
     $offset = $pageSize * ($page - 1);
     if ($offset >= $total) {
         $offset = $total;
     }
     $query->orderBy(' `id` DESC');
     $query->offset($offset);
     $query->limit($pageSize);
     $list = $query->asArray()->all();
     return $this->render('index', ['pages' => $pages, 'total' => $total, 'list' => $list, 'data' => $param, 'model' => $model]);
 }
Example #3
0
 /**
  * Lists all Diary models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = \common\models\Diary::find();
     $query->where(' `status` != :status', [':status' => \common\base\Status::DELETE]);
     $request = Yii::$app->getRequest()->get();
     unset($request['r']);
     $total = $query->count();
     $pageSize = 10;
     $pager = new \common\base\Page();
     $pager->pageName = 'page';
     $pageBarNum = 5;
     $pages = $pager->show($total, $pageSize, $pageBarNum);
     $page = isset($request['page']) ? $request['page'] : 1;
     $offset = $pageSize * ($page - 1);
     if ($offset >= $total) {
         $offset = $total;
     }
     $query->orderBy(' `id` DESC');
     $query->offset($offset);
     $query->limit($pageSize);
     $list = $query->asArray()->all();
     return $this->render('index', ['pages' => $pages, 'total' => $total, 'list' => $list]);
 }