Esempio n. 1
0
 public function run()
 {
     $model = Column::findOne(['short_code' => $this->parent_short_code]);
     $columns = $model->multiSelf;
     //取子列表,仅一层
     if ($columns) {
         return $this->render('side-page', ['title' => $this->title, 'models' => $columns]);
     }
 }
Esempio n. 2
0
 /**
  * 新闻列表
  * @param int $id
  * @return string
  */
 public function actionList()
 {
     $column = Column::findOne(['short_code' => Yii::$app->getRequest()->get('name', '')]);
     if (empty($column)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     //检索与分页
     $query = $column->getImg()->orderBy('publish_at DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['config']['config_site_default_page_size']]]);
     return $this->render('list', ['columnModel' => $column, 'dataProvider' => $dataProvider]);
 }
Esempio n. 3
0
 public function run()
 {
     if (!empty($this->id)) {
         //自动寻找类型
         $class = 'common\\models\\cms\\' . ucfirst($this->controllerId);
         $all = $class::find();
         //选择栏目
         if (!empty($this->short_code)) {
             $all = $all->select($class::tableName() . '.*')->joinWith(['column' => function ($query) {
                 $query->where([Column::tableName() . '.short_code' => $this->short_code]);
             }]);
         }
         //自动判断
         if ($this->actionId == 'view') {
             //详情
             $model = $class::findOne($this->id);
             //在详情中,直接获取栏目
             $all = $all->andWhere(['column_id' => $model->column_id]);
         } elseif ($this->actionId == 'list') {
             //列表
             $column = Column::findOne($this->id);
             //在列表中,直接获取栏目
             $all = $all->andWhere(['column_id' => $column->id]);
         }
         //选择类型
         if (!empty($this->type)) {
             if ($this->type == static::TYPE_N) {
                 //自动取新
                 $all = $all->orderBy($class::tableName() . '.created_at DESC');
             } elseif ($this->type == static::TYPE_V) {
                 //自动取查看最多
                 $all = $all->orderBy($class::tableName() . '.hits DESC');
             } else {
                 //后台指定
                 $all = $all->andFilterWhere(['like', $class::tableName() . '.flag', $this->type]);
             }
         }
         //限制数量
         $models = $all->active()->limit($this->num)->all();
         return $this->render('side-current-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models, 'type' => $this->controllerId]);
     }
 }
Esempio n. 4
0
 /**
  * Finds the Column model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Column the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Column::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }