コード例 #1
0
 public function down()
 {
     $this->dropTable(Rubric::tableName());
     $this->dropTable(RubricTranslate::tableName());
     $this->dropTable(Post::tableName());
     $this->dropTable(PostTranslate::tableName());
 }
コード例 #2
0
ファイル: PostSearch.php プロジェクト: tpoxa/cmars
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->recordsPerPage]]);
     $query->andWhere(['app_id' => \Yii::$app->getModule('cms')->app_id]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->leftJoin(PostTranslate::tableName() . ' as tr ', '' . Post::tableName() . '.id = tr.post_id AND tr.language = \'' . Yii::$app->language . '\'');
     $query->andWhere(['like', 'tr.title', $this->title]);
     $this->addCondition($query, 'alias', true);
     $this->addCondition($query, 'views', true);
     $this->addCondition($query, 'status', true);
     $this->addCondition($query, 'author_id', true);
     return $dataProvider;
 }
コード例 #3
0
ファイル: PostsController.php プロジェクト: tpoxa/cmars
 protected function getTranslateModel($id, $lang)
 {
     $translate = PostTranslate::find()->where(['post_id' => $id, 'language' => $lang])->one();
     if (!$translate) {
         $translate = new PostTranslate();
         $translate->post_id = $id;
         $translate->language = $lang;
     }
     return $translate;
 }
コード例 #4
0
ファイル: Post.php プロジェクト: tpoxa/cmars
 public static function getPostByAlias($alias)
 {
     if ($alias) {
         $sql = "SELECT p.id, pt.full_text, pt.title, pt.meta_title,\n                    pt.meta_descriptions, pt.meta_keywords, pt.preview_text\n                FROM " . Post::tableName() . " as p\n                LEFT JOIN " . PostTranslate::tableName() . " as pt\n                   ON p.id = pt.post_id\n                WHERE pt.language = :lang\n                    AND p.alias = :alias AND p.app_id =:app_id ";
         return PostTranslate::findBySql($sql, [':lang' => Yii::$app->language, ':alias' => $alias, ':app_id' => \Yii::$app->getModule('cms')->app_id])->one();
         $serch = new PostSearch();
         $serch->search([]);
     }
     return false;
 }