コード例 #1
0
ファイル: SideImgTop.php プロジェクト: jorry2008/turen
 public function run()
 {
     $img = Img::find();
     //选择栏目
     if (!empty($this->short_code)) {
         $img = $img->select(Img::tableName() . '.*')->joinWith(['column' => function ($query) {
             $query->where([Column::tableName() . '.short_code' => $this->short_code]);
         }]);
     }
     //选择类型
     if (!empty($this->type)) {
         if ($this->type == static::TYPE_N) {
             //自动取新
             $img = $img->orderBy(Img::tableName() . '.created_at DESC');
         } elseif ($this->type == static::TYPE_V) {
             //自动取查看最多
             $img = $img->orderBy(Img::tableName() . '.hits DESC');
         } else {
             //后台指定
             $img = $img->andFilterWhere(['like', Img::tableName() . '.flag', $this->type]);
         }
     }
     //限制数量
     $models = $img->active()->limit($this->num)->all();
     //     	fb($models);
     if ($models) {
         return $this->render('side-img-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models]);
     }
 }
コード例 #2
0
ファイル: ImgController.php プロジェクト: jorry2008/turen
 /**
  * Finds the Ad model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ad the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Img::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #3
0
ファイル: ImgSearch.php プロジェクト: jorry2008/turen
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Img::find()->alive();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => [], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'column_id' => $this->column_id, 'hits' => $this->hits, 'status' => $this->status, 'deleted' => $this->deleted, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'flag', $this->flag])->andFilterWhere(['like', 'colorval', $this->colorval])->andFilterWhere(['like', 'boldval', $this->boldval])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'link_url', $this->link_url])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'pic_url', $this->pic_url])->andFilterWhere(['like', 'picarr', $this->picarr]);
     return $dataProvider;
 }
コード例 #4
0
ファイル: HomeController.php プロジェクト: jorry2008/turen
 /**
  * 首页
  * @return string
  */
 public function actionIndex()
 {
     $columns = Column::find()->where(['type' => Column::CMS_TYPE_LIST])->active()->orderBy('order ASC')->all();
     //关于我们单页
     $about = Column::find()->where(['short_code' => 'about-brief'])->active()->one();
     //首页主广告
     $mainAdType = AdType::find()->where(['short_code' => 'home_main'])->active()->one();
     //in查询
     $mainAds = $mainAdType->getAd()->active()->orderBy('order ASC')->all();
     //底部广告
     $adBottom = Ad::find()->where(['short_code' => 'home_bottom'])->active()->one();
     //搬家现场,推荐
     $scenes = Img::find()->select(Img::tableName() . '.*')->where(['like', Img::tableName() . '.flag', 'c'])->joinWith(['column' => function ($query) {
         $query->where([Column::tableName() . '.short_code' => 'xianchang']);
     }])->active()->all();
     //搬家现场推荐
     return $this->render('index', ['columns' => $columns, 'about' => $about, 'mainAdType' => $mainAdType, 'mainAds' => $mainAds, 'adBottom' => $adBottom, 'scenes' => $scenes]);
 }
コード例 #5
0
ファイル: Column.php プロジェクト: jorry2008/turen
 /**
  * 一对多
  */
 public function getImg()
 {
     return $this->hasMany(Img::className(), ['column_id' => 'id']);
 }