Yii Framework Forum: Renderpartial Form With Values - Yii Framework Forum

Jump to content

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

Renderpartial Form With Values Rate Topic: -----

#1 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 23 August 2013 - 05:21 AM

Hello, I need help with understanding renderPartial. I have 2 tables:

1)Payments
2)Yearly

When I create Payment I set amount and date, then I send values to Yearly and divide amount etc etc...

When I update Payment I want to get form from Yearly update. Now I have:
Posted Image

But I don't know how to get proper values in my form. Yearly update form should be:
Posted Image


I don't know how should I get values from right model etc ...
Payments/update
<?php echo $this->renderPartial('_form', array('model'=>$model)); 
echo $this->renderPartial('//yearly/_form4up',array('model'=>new Yearly));
?>

0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 575
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 23 August 2013 - 07:52 AM

Seems that you are creating a new model for Yearly try as


$Yearly=Yearly::model()->findByAttributes(array(
 'payment_for'=>$model->attribute_related_in_payment
))
if(!$Yearly){
$Yearly=new Yearly;
}

echo $this->renderPartial('//yearly/_form4up',array('model'=>$Yearly));


In other words, you are not using saved data but creating a new instance of Yearly model.
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 24 August 2013 - 07:01 AM

Yup it works. Now I'm not sure how I can do some stuff like:

- I have now in 1 form two save buttons. Can I do something about it ??

- If I want to set new value for my yearly in 1 form with payment, I should send it from Payment controller ?
0

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 575
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 25 August 2013 - 03:26 AM

What I think is that you are trying to save relative or related model values.

Payment is main model and Yearly is a related or child model having related records about payment.

So, in your controller, you need to do it as

$Yearly=$_POST['Yearly'];
$model=$_POST['Payment'];
if($model->save()){
 $Yearly->payment_id=$model->id;
 $Yearly->save();
}

Same with editing/updating records.
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#5 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 25 August 2013 - 06:43 AM

I'm not sure what i am doing wrong but I get 'Undefined index: Yearly' error when I try to save value in Payment.
0

#6 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 575
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 26 August 2013 - 12:48 AM

You need to debug first what your Yearly form posts i.e. How this form fields are managed in html.

try to do

echo '<pre>'
print_r($_POST);
echo '</pre>';


and check the index of Yearly data
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
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