/** * 发表新帖 * @param Topic $topic * @param bool $active 激活 * @return bool */ public function addTopic(Topic $topic, $active = false) { $topic->setAttributes(['fid' => $this->id]); $result = $topic->save(); if ($result) { $active && $topic->setActive(); return true; } return false; }
public function topicInit() { if ($this->forumId === null) { echo PHP_EOL . '无法创建默认话题,因为没有默认归属版块 ....' . PHP_EOL; return; } echo PHP_EOL . '创建默认话题 ....' . PHP_EOL; $topic = new Topic(); $topic->setAttributes(['fid' => $this->forumId, 'author_id' => 1, 'subject' => '默认话题', 'content' => '默认话题内容']); if ($topic->save()) { $message = '成功'; $this->topic = $topic; } else { $message = '失败'; } echo PHP_EOL . '创建默认话题' . $message . PHP_EOL; }
public function topicInit() { if ($this->forumId === null) { Console::output('无法创建默认话题,因为没有默认归属版块 ....'); return; } Console::output('创建默认话题 ....'); $topic = new Topic(); $topic->setAttributes(['fid' => $this->forumId, 'author_id' => 1, 'subject' => '默认话题', 'content' => '默认话题内容']); if ($topic->save()) { $topic->setActive(); //激活 $message = '成功'; $this->topic = $topic; } else { $message = '失败'; } Console::output('创建默认话题' . $message); }