Yii Framework Forum: data from controller to model - Yii Framework Forum

Jump to content

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

data from controller to model Rate Topic: -----

#1 User is offline   jacbmw 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-October 09
  • Location:Sydney, Australia

Posted 21 October 2009 - 04:58 PM

Basically loading relational data (One Venue has one Address)

In Controller:

$model=$this->loadvenue();
$address=address::model()->findByAttributes(array('venueId'=>$model->id));

....

$this->render('update',array('model'=>$model, 'address'=>$address));


In view:
<?php echo CHtml::activeTextField($model,'website',array('size'=>60,'maxlength'=>145)); ?>

<?php echo CHtml::activeTextField($address,'unit',array('size'=>60,'maxlength'=>145)); ?>

Getting following error when trying to view the update view for Venue:

Undefined variable: address

cheers, Jake
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 21 October 2009 - 06:14 PM

View Postjacbmw, on 21 October 2009 - 04:58 PM, said:

Basically loading relational data (One Venue has one Address)

In Controller:

$model=$this->loadvenue();
$address=address::model()->findByAttributes(array('venueId'=>$model->id));

....

$this->render('update',array('model'=>$model, 'address'=>$address));


In view:
<?php echo CHtml::activeTextField($model,'website',array('size'=>60,'maxlength'=>145)); ?>

<?php echo CHtml::activeTextField($address,'unit',array('size'=>60,'maxlength'=>145)); ?>

Getting following error when trying to view the update view for Venue:

Undefined variable: address

cheers, Jake


If you use the _form.php subview you need to propagate the variable by specifying it in the renderPartial call.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   jacbmw 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-October 09
  • Location:Sydney, Australia

Posted 21 October 2009 - 06:37 PM

Spot on mate, thanks heaps!
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