using $_GET to affect a required model field

First of all I’d like to inform you that I’m a complete noob to Yii and I have this problem:

I’m trying to create a new record using $_GET to have a required model field affected. I wrote this :


$model->IdUsager = $_GET["idu"];

in the _form.php in the view.

With


echo $model->IdUsager;

I was able to confirm that the value has been set in IdUsager but since it’s a required field in the model I keep having a validation error: “Id Usager cannot be blank.”

So I tried to remove the required condition in rule() in the model but then I had an SQL exception because the field was left empty!

Can anyone help me with this?

Thanks a lot.

[color="#FF0000"][Solved][/color]

Thanks to mdomba who answered my PM with this valuable info :

And that was the fix to my problem.

Thanks again mdomba.

Regards.

Mohamed Y.

First of all using $model->IdUsager=$_GET[‘idu’] is a bad practice… you need to check that $_GET[‘idu’] has an intended value or sanitize that value…

As you are new to the framework… if you haven’t already… read the Definitive guide to Yii - http://www.yiiframework.com/doc/guide/

and create a new webapp with yiic shell… then study that code… many things will be more clear to you…

Thank you for your reply, and yes I’m a complete noob on Yii and I have read most of the complete guide but I’m not able to find in it what I’m trying to do. So any other suggestions?

Regards.

Mohamed Y.

Do not just read the guide… make the test application… study the generated code…

After that… if you want to study Yii more … there si the Yii blog tutorial…