コード例 #1
0
 /**
  * @return boolean
  */
 public function create()
 {
     // very, so much, stupid source code :)
     if ($this->validate()) {
         $user = Yii::$app->getUser()->getIdentity();
         // create post
         $post = new Post();
         $post->topic_id = 0;
         $post->message = $this->message;
         $post->save();
         if ($post->save()) {
             // create topic
             $topic = new Topic();
             $topic->subject = $this->subject;
             $topic->post = $post;
             $topic->save();
             // update post.topic_id
             $post->link('topic', $topic);
             $tagNames = explode(',', $this->tags);
             foreach ($tagNames as $tagName) {
                 /** @var Tag $tagModel */
                 $tagModel = Tag::findOne($tagName);
                 $topic->link('tags', $tagModel);
             }
             $this->topic = $topic;
             return true;
         }
     }
     return false;
 }