예제 #1
0
 public function create()
 {
     $question = new Question();
     $question->setAttributes(['subject' => $this->subject, 'content' => $this->content, 'author_id' => $this->author_id]);
     if (($result = $question->save()) && ($result = $question->setActive())) {
         $tags = Tag::findAll(['name' => is_array($this->tags) ? $this->tags : explode(',', $this->tags)]);
         foreach ($tags as $tag) {
             $tagItem = new TagItem();
             $tagItem->setAttributes(['target_id' => $question->id, 'target_type' => $question::TYPE]);
             $tag->addItem($tagItem);
         }
     }
     return $result ? $question : false;
 }
 public function down()
 {
     $this->dropTable(Tag::tableName());
     $this->dropTable(TagItem::tableName());
 }
예제 #3
0
 /**
  * 获取帖子标签记录
  * @return mixed
  */
 public function getTagItems()
 {
     return $this->hasMany(TagItem::className(), ['target_id' => 'id'])->andWhere(['target_type' => self::TYPE]);
 }
예제 #4
0
파일: Tag.php 프로젝트: rocketyang/huajuan
 public function addItem(TagItem $item)
 {
     $item->setAttributes(['tid' => $this->id]);
     return $item->save();
 }