title: yii blog comment model with multimodel form
body: <p>I would like to take the blog comment model and turn the form into a mulitimodel form but I have not been able to work this out. Would appreciate if anyone could point me in the right direction.</p>
  
  <p>Taken the design below I want to add another table (OtherModel) off of comment with a FK in comment linking the tables.</p>
  
  <p><img src="https://i.stack.imgur.com/8MLQ5.png" alt="enter image description here"></p>
  
  <p>Controller</p>
  
  <pre><code>public function actionView()
  {
      $post=$this-&gt;loadModel();
      $comment=$this-&gt;newComment($post);
  
      $this-&gt;render('view',array(
          'model'=&gt;$post,
          'comment'=&gt;$comment,
      ));
  }
  
  protected function newComment($post)
  {
      $comment=new Comment;
      $otherModel=new OtherModel;
      if(isset($_POST['Comment'], $_POST['OtherModel']))
      {
          $comment-&gt;attributes=$_POST['Comment'];
          $otherModel-&gt;attributes=$_POST['OtherModel'];
          if($post-&gt;addComment($comment))
          {
              if($comment-&gt;status==Comment::STATUS_PENDING)
                  Yii::app()-&gt;user-&gt;setFlash('commentSubmitted','Thank you...');
              $this-&gt;refresh();
          }
      }
      return $comment;
  }
  </code></pre>
  
  <p>model</p>
  
  <pre><code>public function addComment($comment)
      {
          $comment-&gt;other_id=$otherModel-&gt;other_id;
          $otherModel-&gt;save();
          if(Yii::app()-&gt;params['commentNeedApproval'])
              $comment-&gt;status=Comment::STATUS_PENDING;
          else
              $comment-&gt;status=Comment::STATUS_APPROVED;
          $comment-&gt;post_id=$this-&gt;id;
          return $comment-&gt;save();
      }
  </code></pre>
  
  <p>render form through CJuiTabs</p>
  
  <pre><code>'Comment'=&gt;$this-&gt;renderPartial('/comment/_form',array($model-&gt;$comment=&gt;),true)
  </code></pre>
  
  <p>form</p>
  
  <pre><code>&lt;div class="form"&gt;
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
          'id'=&gt;'comment-form',
          'enableAjaxValidation'=&gt;true,
  )); ?&gt;
  
          &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
          &lt;div class="row"&gt;
                  &lt;?php echo $form-&gt;labelEx($model,'author'); ?&gt;
                  &lt;?php echo $form-&gt;textField($model,'author',array('size'=&gt;60,'maxlength'=&gt;128)); ?&gt;
                  &lt;?php echo $form-&gt;error($model,'author'); ?&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
                  &lt;?php echo $form-&gt;labelEx($model,'content'); ?&gt;
                  &lt;?php echo $form-&gt;textArea($model,'content',array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt;
                  &lt;?php echo $form-&gt;error($model,'content'); ?&gt;
          &lt;/div&gt;
  
          // added otherModel as part of MMF
          &lt;div class="row"&gt;
                  &lt;?php echo $form-&gt;labelEx($otherModel,'name'); ?&gt;
                  &lt;?php echo $form-&gt;textField($otherModel,'name',array('size'=&gt;60,'maxlength'=&gt;128)); ?&gt;
                  &lt;?php echo $form-&gt;error($otherModel,'name'); ?&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
                  &lt;?php echo $form-&gt;labelEx($otherModel,'description'); ?&gt;
                  &lt;?php echo $form-&gt;textArea($otherModel,'description',array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt;
                  &lt;?php echo $form-&gt;error($otherModel,'description'); ?&gt;
          &lt;/div&gt;
  
          &lt;div class="row buttons"&gt;
                  &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Submit' : 'Save'); ?&gt;
          &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>