Hi,
In advance, sorry for my English.
I work with the framework yii 1.1.7, MySQL database and xampp.
I want to create a user using his name and the project which it is attached (the project name is already created).
Many topics already speaking about that, but I haven’t found an answer to my problem.
Here are some of my database and my code.
database :
TABLE `user` ( `id` ,
`rpi` varchar(7) NOT NULL}
TABLE `userprojet` ( `id` ,
`userId` NOT NULL COMMENT 'constraint foreign key (userId) references user(id)',
`projetName` varchar(12) NOT NULL COMMENT 'constraint foreign key (projetName) references projet(name)'}
TABLE `projetvehicule` ( `id` ,
`name` varchar(12) NOT NULL }
UserController :
public function actionCreate() {
$model = new User;
$modelProjet = new Userprojet;
if(isset($_POST['User'], $_POST['Userprojet']))
{
$model->attributes=$_POST['User'];
$modelProjet->attributes=$_POST['Userprojet'];
//validate BOTH $model and $model
$valid = $model->validate();
$valid = $modelProjet->validate() && $valid;
if($valid)
{
if($model->save(false))
{
$modelProjet->userId = $model->id;
$modelProjet->save(false);
$this->redirect(array('view', 'id' => $model->id));
}
}
}
$this->render('create', array(
'user'=>$model,
'userprojet'=>$modelProjet,
));
}
user/_form :
<?php //echo $form->errorSummary(array($model, $modelProjet)); ?>
<div class="row">
<?php echo $form->labelEx($model,'rpi'); ?>
<?php echo $form->textField($model, 'rpi', array('maxlength' => 7)); ?>
<?php echo $form->error($model,'rpi'); ?>
</div><!-- row -->
<div class="row">
<?php echo $form->labelEx($modelProjet, 'projetName'); ?>
<?php echo $form->dropDownList($modelProjet, 'projetName', GxHtml::listDataEx(Userprojet::model()->findAllAttributes(null, true))); ?>
<?php echo $form->error($modelProjet, 'projetName'); ?>
</div><!-- row -->
user/create :
$this->renderPartial('_form', array(
'user' => $model,
'userprojet'=>$modelProjet,
'buttons' => 'create'));
And in response, I have this error :
Create User
Fields with * are required.
Fatal error: Call to a member function [i]isAttributeRequired[/i]() on a non-object in C:\xampp\htdocs\www\framework\web\helpers\CHtml.php on line 1166
Nothing more
Why is it specified that attributes are required?
I know that all the requested attributes are required.
Regards