Yii Framework Forum: Renderpartial Within A Rendered View - Variable Not Defined - Yii Framework Forum

Jump to content

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

Renderpartial Within A Rendered View - Variable Not Defined Rate Topic: -----

#1 User is offline   Michael Sullivan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 06-February 10

Posted 18 January 2013 - 12:05 PM


I'm trying to display a form to create a new Donations within a view that renders Campaigns or rather a single campaign...

It worked fine displaying the Campaigns data passed to the view, but when I added the code to renderPartial I keep getting a PHP notice "Undefined variable: donations".

In the CampaignsController i am using this code:

	public function actionDisplay($id)
		$params = array('User_ID'=>$campaign->campaign_user);
		if(Yii::app()->user->checkAccess('displayCampaigns') || Yii::app()->user->checkAccess('displayOwnCampaigns',$params)){
			$parts = $this->parts;

		} else {
			throw new CHttpException(403,"You can only display your own Campaign");			


here is the function createDonations() which is also in CampaignsController, and is called by $donations=$this->createDonations($campaign);

	protected function createDonations($campaign) {
		$newdonation = new Donations; 
		if(isset($_POST['Donations'])) {
			if($issue->addDonations($newdonation)) {
				Yii::app()->user->setFlash('donationsSubmitted',"Your Donation has been added." );
		return $newdonation;

In the layout campaignlayout1 I first render data from $campaign and $parts. That worked fine, so I then added a renderPartial() to display the _form from Donations
here is that code:

	<?php $this->renderPartial('/donations/_form',array(
		'model'=>$donations, )); ?>

I get a PHP notice: Undefined variable: donations

here is a portion of the stack trace:

/protected/controllers/CampaignsController.php(232): CController->render("display", array("model" => Campaigns, "parts" => array("banner" => "http://imsgonline.com/yiitest/images/genericbanner.jpg", "avatar" => "http://imsgonline.com/yiitest/images/genericmale.jpg", "copy" => "<p> Send Money </p>", "campaign_name" => "Joes Fundraising"), "donations" => Donations))

Any idea what I'm doing wrong here??

#2 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 703
  • Joined: 12-September 10
  • Location:Austria

Posted 20 January 2013 - 06:33 PM

What variable do you use in the view '/donations/_form'?

If you use $donations there, this is wrong, because you submit this as $model in renderPartial.

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