コード例 #1
0
 public function actionNew()
 {
     $request = Yii::$app->getRequest();
     $topic = new Topic(['scenario' => Topic::SCENARIO_NEW, 'user_id' => Yii::$app->getUser()->id]);
     $content = new TopicContent();
     if ($topic->load($request->post()) && $topic->validate() && $content->load($request->post()) && $content->validate() && $topic->save(false)) {
         $content->link('topic', $topic);
         return $this->redirect(['view', 'id' => $topic->id]);
     }
     return $this->render('new', ['model' => $topic, 'content' => $content]);
 }