public function assignRule() { if (isset(Yii::$app->getModule('seo')->installed) && Yii::$app->getModule('seo')->installed) { $seo = SeoMeta::find()->where(['not', ['url' => null]])->andWhere(['not', ['route' => null]])->all(); foreach ($seo as $meta) { $this->rules[$meta->url] = $meta->route; } } }
public function actionDelete($id) { if ($model = SeoMeta::findOne($id)) { $model->delete(); } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/menu', 'News deleted')); }
/** * Module database install * */ public function dbInstall() { $db = Yii::$app->db; $tableOptions = null; if ($db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM'; } $db->createCommand()->createTable(SeoMeta::tableName(), ['id' => Schema::TYPE_INTEGER . '(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'label' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'type' => Schema::TYPE_STRING . '(25) DEFAULT "page"', 'url' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'params' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'route' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'tags' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'robots' => 'TINYINT(1) UNSIGNED NOT NULL DEFAULT 0', 'status' => 'TINYINT(1) UNSIGNED NOT NULL', 'updated_at' => Schema::TYPE_INTEGER . '(11) UNSIGNED DEFAULT NULL ', 'created_at' => Schema::TYPE_INTEGER . '(11) UNSIGNED DEFAULT NULL'], $tableOptions)->execute(); $db->createCommand()->createIndex('idx_route', SeoMeta::tableName(), 'route', true)->execute(); $db->createCommand()->createTable(SeoRedirects::tableName(), ['id' => Schema::TYPE_INTEGER . '(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'old_url' => Schema::TYPE_STRING . '(255) NOT NULL', 'new_url' => Schema::TYPE_STRING . '(255) NOT NULL DEFAULT "/"', 'updated_at' => Schema::TYPE_INTEGER . '(11) UNSIGNED DEFAULT NULL ', 'created_at' => Schema::TYPE_INTEGER . '(11) UNSIGNED DEFAULT NULL', 'status' => 'ENUM("301","302") NOT NULL DEFAULT "301"'], $tableOptions)->execute(); $db->createCommand()->createIndex('idx_old_url', SeoRedirects::tableName(), 'old_url', true)->execute(); }
/** * Get data from database * * @param string $route * @param array $params */ protected function _getMetaData($route, $params = null) { $params = json_encode($params); /*$model = SeoMeta::find() ->where(['route' => '-']) ->orWhere( ['and', 'route=:route', ['or', 'params IS NULL', 'params=:params']], [':route' => $route, ':params' => $params] )->asArray() ->all(); */ $item = SeoMeta::find()->where(['and', 'route=:route', ['or', 'params IS NULL', 'params=:params']], [':route' => $route, ':params' => $params])->asArray()->one(); if (isset($item)) { $seo = yii\easyii\models\SeoText::find()->where(['class' => SeoMeta::className(), 'item_id' => $item['id']])->asArray()->one(); if (isset($seo)) { $item = ArrayHelper::merge($item, $seo); } $item = array_filter($item, 'strlen'); if (!empty($item['tags'])) { $item['tags'] = (array) json_decode($item['tags']); } if ($item['route'] == '-') { $this->_defaultMetaData = $item; } elseif ($item['route'] != '-' && empty($item['params'])) { $this->_routeMetaData = $item; } elseif ($item['route'] != '-' && !empty($item['params'])) { $this->_paramsMetaData = $item; } } /* foreach($model AS $item) { $item = array_filter($item, 'strlen'); if(!empty($item['tags'])) $item['tags'] = (array)json_decode($item['tags']); if($item['route'] == '-') $this->_defaultMetaData = $item; elseif($item['route'] != '-' && empty($item['params'])) $this->_routeMetaData = $item; elseif($item['route'] != '-' && !empty($item['params'])) $this->_paramsMetaData = $item; } */ }