/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Type::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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]); $query->andFilterWhere(['like', 'tag', $this->tag])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionIndex($type) { $type = Type::findOne(['tag' => $type]); $dataProvider = new ActiveDataProvider(['query' => $type->getArticles()->orderBy('create_at desc'), 'pagination' => ['pageSize' => 20]]); return $this->render('index', ['dataProvider' => $dataProvider, 'type' => $type]); }
use xuguoliangjj\ueditor\UEditor; use yii\helpers\ArrayHelper; use backend\modules\blog\models\Type; /* @var $this yii\web\View */ /* @var $model backend\modules\blog\models\Article */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="article-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'type_id')->dropDownList(ArrayHelper::map(Type::find()->asArray()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'content')->textarea()->widget(UEditor::className(), ['options' => []]); ?> <?php echo $form->field($model, 'status')->dropDownList(['0' => '草稿', '1' => '发布']); ?> <?php
/** * Finds the Type model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Type the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Type::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getType() { return $this->hasOne(Type::className(), ['id' => 'type_id']); }