コード例 #1
0
 /**
  * Runs the action
  *
  * @return string result content
  */
 public function run($slug)
 {
     if ($link = Link::findOne(['slug' => $slug])) {
         $statusCode = empty($link->status_code) ? $this->defaultStatusCode : $link->status_code;
         return Yii::$app->getResponse()->redirect($link->url, $statusCode);
     } else {
         throw new \yii\web\NotFoundHttpException('Page not found.');
     }
 }
コード例 #2
0
ファイル: LinkSearch.php プロジェクト: yeesoft/yii2-yee-link
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Link::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => 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, 'status_code' => $this->status_code, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }