Send data to form

Hi @ all,

how is it possible to send data to a create-form.

I am in a view of another Model an now I want to define a link (for example “<?php echo CHtml::link(“Hello”,array(‘bla/create’)); ?>”) to create a new “bla”. But I know already some attributes of the new “bla”. How can I send this data to the Form and disable the fields? What is the yii-way to do this.

Thanks for any help

In your actionCreate of your controller, just set the attributes of the model before you render the view. They will show up in your form.

OK, but how is it possible to tell method actionCreate the attributes from an other view?

If I create the Link <?php echo CHtml::link(“Hello”,array(‘bla/create’)); ?> I get a new form without any filled fields.

An Example:

I have 2 models: Father and child

Father has many childs

In the view of father I want define an add button to create a new child. In this view I know the father_id. So I want that the field father_id in the create Form is already filled and disabled.

You have to create the link like that:

CHtml::link('add child', array('child/create', 'father_id'=>$father->id));

This link will pass via get the data to the create.

In the create you can do like that:

action create()


   $model=new Child();




Yeah, thanks!

I didn’t know how to put the data in $_GET with CHtml::link

Is this the usual way to do this in yii?

Thank you

Yes, is the usual way.

For put data in the $_POST method, check here.