mentorq
(Mentorq)
1
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:

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

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));
?>
perochak
(Amjad Mughal)
2
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.
mentorq
(Mentorq)
3
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 ?
perochak
(Amjad Mughal)
4
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.
mentorq
(Mentorq)
5
I’m not sure what i am doing wrong but I get ‘Undefined index: Yearly’ error when I try to save value in Payment.
perochak
(Amjad Mughal)
6
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