dimis283
(Dimis283)
March 17, 2010, 2:37pm
1
Is there a way a CActiveForm to have a field of a model that have a relation to a model?
<?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>
cyberpol
(Cyberpol 777)
March 17, 2010, 3:02pm
2
If I not wrong you can use this way:
<?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.
If I not wrong you can use this way:
<?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