diff --git a/controllers/SeoController.php b/controllers/SeoController.php index 676a9f7..178a4b8 100755 --- a/controllers/SeoController.php +++ b/controllers/SeoController.php @@ -1,182 +1,134 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => [ - 'site' => [ - [ - 'actions' => [ - 'login', - 'error', - ], - 'allow' => true, - ], - ], - ], - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - - ], - ]; - } - - /** - * Lists all Seo models. - * - * @return mixed - */ - public function actionIndex() - { - $searchModel = new SeoSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render( - 'index', - [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ] - ); - } - - /** - * Displays a single Seo model. - * - * @param integer $id - * - * @return mixed - */ - public function actionView($id) - { - return $this->render( - 'view', - [ - 'model' => $this->findModel($id), - ] - ); - } - - /** - * Creates a new Seo model. - * If creation is successful, the browser will be redirected to the 'view' page. - * - * @return mixed - */ - public function actionCreate() - { - $model = new Seo(); - $model->generateLangs(); - - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - return $this->redirect( + return [ + 'access'=>[ + 'class' => AccessBehavior::className(), + 'rules' => + ['site' => [ - 'view', - 'id' => $model->id, - ] - ); - } - } - return $this->render( - 'create', - [ - 'model' => $model, - 'modelLangs' => $model->modelLangs, - ] - ); - } - - /** - * Updates an existing Seo model. - * If update is successful, the browser will be redirected to the 'view' page. - * - * @param integer $id - * - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - $model->generateLangs(); - if ($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request); - if ($model->save() && $model->transactionStatus) { - return $this->redirect( - [ - 'view', - 'id' => $model->id, + [ + 'actions' => ['login', 'error'], + 'allow' => true, + ] ] - ); - } - } - return $this->render( - 'update', - [ - 'model' => $model, - 'modelLangs' => $model->modelLangs, - ] - ); + ] + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all Seo models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Seo model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Seo model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Seo(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->seo_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); } - - /** - * Deletes an existing Seo model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * - * @param integer $id - * - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id) - ->delete(); - - return $this->redirect([ 'index' ]); + } + + /** + * Updates an existing Seo model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->seo_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); } - - /** - * Finds the Seo model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * - * @param integer $id - * - * @return Seo the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (( $model = Seo::find() - ->where([ 'id' => $id ]) - ->with('lang') - ->one() ) !== null - ) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } + } + + /** + * Deletes an existing Seo model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Seo model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Seo the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Seo::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); } } +} diff --git a/models/Seo.php b/models/Seo.php index eba94b6..d81674d 100755 --- a/models/Seo.php +++ b/models/Seo.php @@ -1,85 +1,55 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [ - [ 'url' ], - 'required', - ], - [ - [ 'url' ], - 'string', - 'max' => 255, - ], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => Yii::t('app', 'seo_id'), - 'url' => Yii::t('app', 'url'), - ]; - } + return 'seo'; } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['url'], 'required'], + [['seo_text'], 'string'], + [['url', 'title', 'meta', 'description', 'h1'], 'string', 'max' => 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_id' => Yii::t('app', 'seo_id'), + 'url' => Yii::t('app', 'url'), + 'title' => Yii::t('app', 'title'), + 'meta' => Yii::t('app', 'meta_title'), + 'description' => Yii::t('app', 'description'), + 'h1' => Yii::t('app', 'h1'), + 'seo_text' => Yii::t('app', 'seo_text'), + ]; + } +} diff --git a/models/SeoLang.php b/models/SeoLang.php deleted file mode 100755 index a4db5b2..0000000 --- a/models/SeoLang.php +++ /dev/null @@ -1,123 +0,0 @@ - 255, - ], - [ - [ - 'seo_id', - 'language_id', - ], - 'unique', - 'targetAttribute' => [ - 'seo_id', - 'language_id', - ], - 'message' => 'The combination of Seo ID and Language ID has already been taken.', - ], - [ - [ 'language_id' ], - 'exist', - 'skipOnError' => true, - 'targetClass' => Language::className(), - 'targetAttribute' => [ 'language_id' => 'id' ], - ], - [ - [ 'seo_id' ], - 'exist', - 'skipOnError' => true, - 'targetClass' => Seo::className(), - 'targetAttribute' => [ 'seo_id' => 'id' ], - ], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'seo_id' => Yii::t('app', 'seo_id'), - 'language_id' => Yii::t('app', 'language_id'), - 'title' => Yii::t('app', 'title'), - 'meta_description' => Yii::t('app', 'meta_description'), - 'h1' => Yii::t('app', 'h1'), - 'meta' => Yii::t('app', 'meta'), - 'seo_text' => Yii::t('app', 'seo_text'), - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getLanguage() - { - return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getSeo() - { - return $this->hasOne(Seo::className(), [ 'id' => 'seo_id' ]); - } - } diff --git a/models/SeoSearch.php b/models/SeoSearch.php index 03e7754..584f62f 100755 --- a/models/SeoSearch.php +++ b/models/SeoSearch.php @@ -1,168 +1,74 @@ joinWith('lang'); - - // add conditions that should always apply here - - $dataProvider = new ActiveDataProvider( - [ - 'query' => $query, - 'sort' => [ - 'attributes' => [ - 'id', - 'url', - 'title' => [ - 'asc' => [ 'seo_lang.title' => SORT_ASC ], - 'desc' => [ 'seo_lang.title' => SORT_DESC ], - ], - 'meta_description' => [ - 'asc' => [ 'seo_lang.meta_description' => SORT_ASC ], - 'desc' => [ 'seo_lang.meta_description' => SORT_DESC ], - ], - 'h1' => [ - 'asc' => [ 'seo_lang.h1' => SORT_ASC ], - 'desc' => [ 'seo_lang.h1' => SORT_DESC ], - ], - 'meta' => [ - 'asc' => [ 'seo_lang.meta' => SORT_ASC ], - 'desc' => [ 'seo_lang.meta' => SORT_DESC ], - ], - 'seo_text' => [ - 'asc' => [ 'seo_lang.seo_text' => SORT_ASC ], - 'desc' => [ 'seo_lang.seo_text' => 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; - } - - // grid filtering conditions - $query->andFilterWhere( - [ - 'id' => $this->id, - ] - ); - - $query->andFilterWhere( - [ - 'like', - 'url', - $this->url, - ] - ) - ->andFilterWhere( - [ - 'ilike', - 'seo_lang.title', - $this->title, - ] - ) - ->andFilterWhere( - [ - 'ilike', - 'seo_lang.meta_description', - $this->meta_description, - ] - ) - ->andFilterWhere( - [ - 'ilike', - 'seo_lang.h1', - $this->h1, - ] - ) - ->andFilterWhere( - [ - 'ilike', - 'seo_lang.meta', - $this->meta, - ] - ) - ->andFilterWhere( - [ - 'ilike', - 'seo_lang.seo_text', - $this->seo_text, - ] - ); - + return [ + [['seo_id'], 'integer'], + [['url', 'title', 'meta', 'description', 'h1', 'seo_text'], 'safe'], + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Seo::find(); + + // add conditions that should always apply here + + $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; } + + // grid filtering conditions + $query->andFilterWhere([ + 'seo_id' => $this->seo_id, + ]); + + $query->andFilterWhere(['like', 'url', $this->url]) + ->andFilterWhere(['like', 'title', $this->title]) + ->andFilterWhere(['like', 'meta', $this->meta]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'h1', $this->h1]) + ->andFilterWhere(['like', 'seo_text', $this->seo_text]); + + return $dataProvider; } +} diff --git a/views/seo/_form.php b/views/seo/_form.php index 426df22..9853be6 100755 --- a/views/seo/_form.php +++ b/views/seo/_form.php @@ -1,37 +1,41 @@
- = Html::a(\Yii::t('app', 'create_item',['item'=>'Seo']), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> + = Html::a(Yii::t('app', 'Create Seo'), ['create'], ['class' => 'btn btn-success']) ?>
- = GridView::widget( - [ - 'dataProvider' => $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - [ 'class' => 'yii\grid\SerialColumn' ], - 'id', - 'url', - [ - 'attribute' => 'title', - 'value' => 'lang.title', - ], - [ - 'attribute' => 'meta_description', - 'value' => 'lang.meta_description', - ], - [ - 'attribute' => 'h1', - 'value' => 'lang.h1', - ], - [ - 'attribute' => 'meta', - 'value' => 'lang.meta', - ], - [ - 'attribute' => 'seo_text', - 'value' => 'lang.seo_text', - ], - [ 'class' => 'yii\grid\ActionColumn' ], - ], - ] - ); ?> + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'seo_id', + 'url:url', + 'meta', + 'h1', + // 'seo_text:ntext', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?>- = Html::a( - Yii::t('app', 'Update'), - [ - 'update', - 'id' => $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - = Html::a( - Yii::t('app', 'Delete'), - [ - 'delete', - 'id' => $model->id, + = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->seo_id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->seo_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', ], - [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), - 'method' => 'post', - ], - ] - ) ?> + ]) ?>
- - = DetailView::widget( - [ - 'model' => $model, - 'attributes' => [ - 'id', - 'url', - 'lang.title', - 'lang.meta_description', - 'lang.h1', - 'lang.meta', - 'lang.seo_text', - ], - ] - ) ?> + + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'seo_id', + 'url:url', + 'title', + 'meta', + 'description', + 'h1', + 'seo_text:ntext', + ], + ]) ?>