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 @@
- + - - field($model, 'url') - ->textInput([ 'maxlength' => true ]) ?> - - $modelLangs, - 'formView' => '@artweb/artbox/seo/views/seo/_form_language', - 'form' => $form, - ]) ?> - + + field($model, 'url')->textInput(['maxlength' => true]) ?> + + field($model, 'title')->textInput(['maxlength' => true]) ?> + + field($model, 'meta')->textInput(['maxlength' => true]) ?> + + field($model, 'description')->textInput(['maxlength' => true]) ?> + + field($model, 'h1')->textInput(['maxlength' => true]) ?> + field($model, 'seo_text')->widget(CKEditor::className(), + [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ + 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, //по умолчанию false]), + 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') + ] + ) + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
- +
diff --git a/views/seo/_form_language.php b/views/seo/_form_language.php deleted file mode 100755 index 8a0cdda..0000000 --- a/views/seo/_form_language.php +++ /dev/null @@ -1,43 +0,0 @@ - -field($model_lang, '[' . $language->id . ']title') - ->textInput([ 'maxlength' => true ]); ?> - -field($model_lang, '[' . $language->id . ']meta_description') - ->widget(CKEditor::className(), [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ - 'preset' => 'full', - 'inline' => false, - 'filebrowserUploadUrl' => Yii::$app->getUrlManager() - ->createUrl('file/uploader/images-upload'), - ]), - ]) ?> - -field($model_lang, '[' . $language->id . ']seo_text') - ->widget(CKEditor::className(), [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ - 'preset' => 'full', - 'inline' => false, - 'filebrowserUploadUrl' => Yii::$app->getUrlManager() - ->createUrl('file/uploader/images-upload'), - ]), - ]) ?> - -field($model_lang, '[' . $language->id . ']h1') - ->textInput([ 'maxlength' => true ]) ?> - -field($model_lang, '[' . $language->id . ']meta') - ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/views/seo/_search.php b/views/seo/_search.php new file mode 100755 index 0000000..aa869f7 --- /dev/null +++ b/views/seo/_search.php @@ -0,0 +1,39 @@ + + + diff --git a/views/seo/create.php b/views/seo/create.php index 6f72116..fb2601c 100755 --- a/views/seo/create.php +++ b/views/seo/create.php @@ -1,30 +1,21 @@ title = \Yii::t('app', 'create_item',['item'=>'Seo']); - $this->params[ 'breadcrumbs' ][] = [ - 'label' => Yii::t('app', 'Seos'), - 'url' => [ 'index' ], - ]; - $this->params[ 'breadcrumbs' ][] = $this->title; + +use yii\helpers\Html; + + +/* @var $this yii\web\View */ +/* @var $model common\models\Seo */ + +$this->title = Yii::t('app', 'Create Seo'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'modelLangs' => $modelLangs, + 'model' => $model, ]) ?>
diff --git a/views/seo/index.php b/views/seo/index.php index 0143067..1118984 100755 --- a/views/seo/index.php +++ b/views/seo/index.php @@ -1,53 +1,36 @@ title = Yii::t('app', 'Seo'); - $this->params[ 'breadcrumbs' ][] = $this->title; + +use yii\helpers\Html; +use yii\grid\GridView; + +/* @var $this yii\web\View */ +/* @var $searchModel common\models\SeoSearch */ +/* @var $dataProvider yii\data\ActiveDataProvider */ + +$this->title = Yii::t('app', 'Seo'); +$this->params['breadcrumbs'][] = $this->title; ?>
- +

title) ?>

- + render('_search', ['model' => $searchModel]); ?> +

- 'Seo']), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> + 'btn btn-success']) ?>

- $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' ], - ], - ] - ); ?> + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'seo_id', + 'url:url', + 'meta', + 'h1', + // 'seo_text:ntext', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?>
diff --git a/views/seo/update.php b/views/seo/update.php index 8fb5b6e..0cdcc84 100755 --- a/views/seo/update.php +++ b/views/seo/update.php @@ -1,46 +1,23 @@ title = Yii::t( - 'app', - 'Update {modelClass}: ', - [ - 'modelClass' => 'Seo', - ] - ) . $model->url; - $this->params[ 'breadcrumbs' ][] = [ - 'label' => Yii::t('app', 'Seos'), - 'url' => [ 'index' ], - ]; - $this->params[ 'breadcrumbs' ][] = [ - 'label' => $model->url, - 'url' => [ - 'view', - 'id' => $model->id, - ], - ]; - $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); + +use yii\helpers\Html; + +/* @var $this yii\web\View */ +/* @var $model common\models\Seo */ + +$this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo', +]) . $model->title; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->seo_id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- - render( - '_form', - [ - 'model' => $model, - 'modelLangs' => $modelLangs, - ] - ) ?> + + render('_form', [ + 'model' => $model, + ]) ?>
diff --git a/views/seo/view.php b/views/seo/view.php index 1f97289..fa1330f 100755 --- a/views/seo/view.php +++ b/views/seo/view.php @@ -1,61 +1,41 @@ title = $model->url; - $this->params[ 'breadcrumbs' ][] = [ - 'label' => Yii::t('app', 'Seos'), - 'url' => [ 'index' ], - ]; - $this->params[ 'breadcrumbs' ][] = $this->title; + +use yii\helpers\Html; +use yii\widgets\DetailView; + +/* @var $this yii\web\View */ +/* @var $model common\models\Seo */ + +$this->title = $model->title; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; ?>
- +

title) ?>

- +

- $model->id, - ], - [ 'class' => 'btn btn-primary' ] - ) ?> - $model->id, + $model->seo_id], ['class' => 'btn btn-primary']) ?> + $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', - ], - ] - ) ?> + ]) ?>

- - $model, - 'attributes' => [ - 'id', - 'url', - 'lang.title', - 'lang.meta_description', - 'lang.h1', - 'lang.meta', - 'lang.seo_text', - ], - ] - ) ?> + + $model, + 'attributes' => [ + 'seo_id', + 'url:url', + 'title', + 'meta', + 'description', + 'h1', + 'seo_text:ntext', + ], + ]) ?>
-- libgit2 0.21.4