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

Hi

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)
	{
		$campaign=$this->loadModel($id);
		$donations=$this->createDonations($campaign);
		$params = array('User_ID'=>$campaign->campaign_user);
		if(Yii::app()->user->checkAccess('displayCampaigns') || Yii::app()->user->checkAccess('displayOwnCampaigns',$params)){
			$this->parts=array(
				'banner'=>Images::model()->getImageUrl($campaign->campaign_banner),
				'avatar'=>Images::model()->getImageUrl($campaign->campaign_avatar),
				'copy'=>$campaign->campaign_copy,
				'campaign_name'=>$campaign->campaign_name,
			);
			
			$parts = $this->parts;
			$this->layout='//layouts/campaignlayout1';
			$this->render('display',array(
				'model'=>$campaign,
				'parts'=>$parts,
				'donations'=>$donations,
			));

		} 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'])) {
			$newdonation->attributes=$_POST['Donations']; 
			if($issue->addDonations($newdonation)) {
				Yii::app()->user->setFlash('donationsSubmitted',"Your Donation has been added." );
				$this->refresh(); 
			}
		
		}
		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??
0

#2 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 678
  • 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.
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