<?php $form=$this->beginWidget('CActiveForm', array( 'action'=>Yii::app()->createUrl($this->route), 'method'=>'get', )); ?> <div class="row"> <?php echo $form->label($model,'cats->NAME'); ?>//cats has a relation with //that model <?php echo $form->textField($model,'cats->NAME'); ?> </div>
Page 1 of 1
forms and relations
#1
Posted 17 March 2010 - 09:37 AM
Is there a way a CActiveForm to have a field of a model that have a relation to a model?

#2
Posted 17 March 2010 - 10:02 AM
If I not wrong you can use this way:
Where cats MUST BE the name of the relation (declared in relations()).
And of course NAME must be a property (field) of the related model.
<?php echo $form->textField($model,'cats.NAME'); ?>
Where cats MUST BE the name of the relation (declared in relations()).
And of course NAME must be a property (field) of the related model.
Don't say what you think, think what you say
The problem is communication! Excess of communication!
The problem is communication! Excess of communication!
#3
Posted 28 March 2013 - 04:46 AM
PoL, on 17 March 2010 - 10:02 AM, said:
If I not wrong you can use this way:
Where cats MUST BE the name of the relation (declared in relations()).
And of course NAME must be a property (field) of the related model.
<?php echo $form->textField($model,'cats.NAME'); ?>
Where cats MUST BE the name of the relation (declared in relations()).
And of course NAME must be a property (field) of the related model.
nope. Didn't work for me for some reason.
I have a relation with the name "user", I tried to access the described way. The label worked fine, but once I tried to pull the same trick with the TextField, I got an error "property "Offer.user.gender" is not defined."
<?php echo $form->label($model,'user.gender'); ?> <?php echo $form->textField($model,'user.gender'); ?>
Somehow, the label function considered it to be defined whereas the textField one thought the opposite
Share this topic:
Page 1 of 1