示例#1
0
 public function actionRead($id)
 {
     $this->assign('article', $art = BlogPost::findByPk($id));
     if ($art->allow_comments) {
         $model = new BlogComment();
         $model->post_id = $id;
         if (isset($_POST['BlogComment']) && $model->setAttributes($_POST['BlogComment'])->save()) {
             Messages::get()->success("Comment saved!");
             $this->goBack();
         }
         $this->assign('model', $model);
         $this->assign('comments', BlogComment::findAllByAttributes(['post_id' => $id, 'status' => BlogComment::STATUS_OK]));
     }
 }
示例#2
0
 /**
  * Return list of relations for current model
  * @return array
  */
 public static function getRelations()
 {
     return ['author' => [DbRelations::BELONGS_TO, '\\app\\models\\User', 'author_id'], 'category' => [DbRelations::BELONGS_TO, '\\mpf\\modules\\blog\\models\\BlogCategory', 'category_id'], 'comments' => [DbRelations::HAS_MANY, BlogComment::className(), 'post_id'], 'editor' => [DbRelations::BELONGS_TO, '\\app\\models\\User', 'edited_by']];
 }