Yii Framework Forum: forms and relations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

forms and relations Rate Topic: -----

#1 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

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?
<?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>

Posted Image
0

#2 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 17 March 2010 - 10:02 AM

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.

Don't say what you think, think what you say
The problem is communication! Excess of communication!
0

#3 User is offline   AlmostHuman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-February 13

Posted 28 March 2013 - 04:46 AM

View PostPoL, on 17 March 2010 - 10:02 AM, said:

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users