public function actionIndex($hrurl) { $url = Url::find()->byUrl($hrurl); if (!$url) { throw new NotFoundHttpException(); } $model = Page::findOne(['url' => $url->id]); if (!$model) { throw new NotFoundHttpException(); } return $this->render('index', ['hrurl' => $hrurl, 'url' => $url, 'model' => $model]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Url::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', 'url', $this->url]); return $dataProvider; }
<?php echo $form->field($model, 'content')->widget(TinyMCE::className()); ?> <?php if ($model->url !== null) { $pages = Page::find()->where(['!=', 'url', $model->url])->all(); } else { $pages = Page::find()->all(); } $usedUrlsIds = array_map(function ($page) { return $page->url; }, $pages); ?> <?php echo $form->field($model, 'url')->widget(Select2Widget::className(), ['items' => ArrayHelper::map(Url::find()->where(['not in', 'id', $usedUrlsIds])->all(), 'id', 'url')]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getUrl0() { return $this->hasOne(Url::className(), ['id' => 'url']); }
/** * Finds the Url model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Url the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Url::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }