hi.
I have two tables student and user . From the students form I wish to send some data to student table and some to user table .
In studentController my code is
public function actionCreate()
{
$model=new Student;
$model2=new User;
if(isset($_POST['Student']))
{
$model->attributes=$_POST['Student'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
$model2->attributes=$_POST['User'];
if($model2->save())
$this->redirect(array('view','id'=>$model2->id));
}
$this->render('create',array(
'model'=>$model,
'model2'=>$model2,
));
}
In student.php my code is
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('fName', 'length', 'max'=>250),
array('name, email', 'length', 'max'=>50),
array('nic', 'length', 'max'=>10),
array('user_id', 'length', 'max'=>20),
//array('user_id', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, name, nic,fName, email', 'safe', 'on'=>'search'),
);
}
[b]In _form.php my code is
[/b]
<?php echo $form->errorSummary($model,$model2); ?>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model2,'user_id'); ?>
<?php echo $form->textField($model2,'user_id',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model2,'user_id'); ?>
</div>
after exectuion I get the error
[i]
Property "Student.user_id" is not defined. [/i]
i dont understand why???