Cactive Form For 2 Models, Can Only Get Parameters From 1...

Dear all,

I am using CActiveform to handle 2 models, "Favorites" and "Mycat"

Here are some of my codes:

Form:


<?php $form=$this->beginWidget('CActiveForm', array(

        'id'=>'favorite-form',

	'focus'=>array($favorite, 'category_id'),

)); ?>


<?php 

echo $form->textField($favorite,'subscribe',array('value'=>1)); 

?>


<?php echo $form->error($favorite,'subscribe'); ?>

&nbsp&nbsp&nbsp

Or

&nbsp&nbsp&nbsp

<?php } ?>


<?php echo $form->textField($mycat,'name',array('placeholder'=>'Create a new category', 'size'=>30,'maxlength'=>30,'style'=>'width:200px;')); ?>

<?php echo $form->error($mycat,'name'); ?> 


</div>

 

<div class="modal-footer">


<?php echo CHtml::submitButton('Save', array('class'=>'btn btn-success','style'=>'margin-right:20px;')); ?>




<?php $this->endWidget(); ?>

My controller:


    


   protected function favorite($id,$mycat){

    $favorite = new Favorites;

    $favorite->questions_id = $id;

    if(isset($_POST['Favorites'])){

    $favorite->owner_id = Yii::app()->user->id;

    $favorite->create_time = time();

    $favarite->attributes = $_POST['Favorites'];


    if(isset($_POST['Mycat'])){

    $mycat->attributes=$_POST['Mycat'];

    } //if post mycat


    if($mycat->name){

    $mycat->create_time = time();

    $mycat->owner_id = Yii::app()->user->id;

    if($mycat->save()){

    $favorite->category_id = $mycat->id;

                      }

    } //if mycat not empty


    $favorite->save();

    }//if post favorites


       return $favorite;

   }

And I render this in actionView


            $mycat = new Mycat;

            $favorite = $this->favorite($id,$mycat);

However, only attributes from model Mycat is collected, all attributes from model Favorites will be ignored and not be included in $_POST[‘Favorites’];

Any ideas?

Thanks!!!

Hi

Did you pass as parameters both $mycat and $favories from your action to your view?

check in actionUpdate if all the stored data displayed on your form

change the order





    $favarite->attributes = $_POST['Favorites'];

    $favorite->owner_id = Yii::app()->user->id;

    $favorite->create_time = time();