可能重复:
PHP:“注意:未定义的变量”和“注意:未定义的索引”</a>
我正在尝试显示一个表单以在呈现活动或更确切地说是单个活动的视图中创建一个新的捐赠...
它可以很好地显示传递给视图的活动数据,但是当我将代码添加到 renderPartial 时,我不断收到 PHP 通知“未定义的变量:捐赠”。
在 CampaignsController 我使用此代码:
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");
}
}
这是也在 CampaignsController 中的函数 createDonations(),由 $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;
}
在布局campaignlayout1 中,我首先渲染来自$campaign 和$parts 的数据。效果很好,所以我添加了一个 renderPartial() 来显示来自捐赠的 _form - 这是代码:
<?php $this->renderPartial('/donations/_form',array(
'model'=>$donations, )); ?>
我收到一条 PHP 通知:未定义变量:捐赠
这是堆栈跟踪的一部分:
/protected/controllers/CampaignsController.php(232): CController->render("display", array("model" => Campaigns, "parts" => array("banner" => " http://imsgonline.com /yiitest/images/genericbanner.jpg ", "头像" => " http://imsgonline.com/yiitest/images/genericmale.jpg ", "复制" => "
寄钱
", "campaign_name" => "Joes Fundraising"), "donations" => Donations))知道我在这里做错了什么吗?