我认为我在代码中做得很好,但是这个错误来自于我不知道在哪里 请帮助我,我新的 cakephp * 。
错误 显示是:
注意(8):未定义的变量:officename [APP \ Controller \ EnduserController.php,第84行]
注意(8):未定义的变量:visitdays [APP \ Controller \ EnduserController.php,第85行]
注意(8):未定义的变量:from_time [APP \ Controller \ EnduserController.php,第86行]
注意(8):未定义的变量:to_time [APP \ Controller \ EnduserController.php,第87行]
请帮助!!!!! 这是我的代码:
我的控制器 / EnduserController / doctorscheduleend: doctorscheduleend行动
public function doctorscheduleend()
{
$this->layout = 'ajax';
$this->autoRender = false;
$this->loadModel('DoctorSchedule');
$this->loadModel('Doctor');
$this->loadModel('Office');
$doctor_name = $this->Doctor->find('all',array('fields'=>array('Doctor.first_name','Doctor.last_name'),'conditions'=>array('Doctor.id'=>$_POST['DoctorId'])));
$this->set('doctor_name',$doctor_name);
foreach($doctor_name as $row)
{
$doctor_first_name = $row['Doctor']['first_name'];
$doctor_last_name = $row['Doctor']['last_name'];
}
$schedule = $this->DoctorSchedule->find('all',array('fields'=>array('DoctorSchedule.office_id','DoctorSchedule.visitdays','DoctorSchedule.from_time','DoctorSchedule.to_time'),'conditions'=>array('DoctorSchedule.doctor_id'=>$_POST['DoctorId'])));
$this->set('schedule',$schedule);
foreach($schedule as $row)
{
$office_id = $row['DoctorSchedule']['office_id'];
$visitdays = $row['DoctorSchedule']['visitdays'];
$from_time = $row['DoctorSchedule']['from_time'];
$to_time = $row['DoctorSchedule']['to_time'];
}
$office = $this->Office->find('all',array('fields'=>array('Office.office_name'),'conditions'=>array('Office.id'=>['$office_id'])));/*editted here $officeid to ['$office_id']*/
foreach($office as $row)
{
$officename = $row['Office']['office_name'];
}
$tablerows = "";
$tablerows.= "<tr>
<td colspan='4' style='color:white;'>Schedule Of Dr. ".$doctor_first_name." ".$doctor_last_name."</td></tr></br>
<tr>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>Hospital</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>Visitday</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>From</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>To</th>
</tr>
<tr>
<td>".$officename."</td>
<td>".$visitdays."</td>
<td>".$from_time."</td>
<td>".$to_time."</td>
</tr>";
echo $tablerows;
}
我的模型 DoctorSchedule:
<?php
class DoctorSchedule extends AppModel {
public $name='DoctorSchedule';
public $validate = array(
'name' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A State Name is required'
)
),
'country_id' => array('notempty' => array(
'rule' => array('notempty'),
'message' => 'Please Select Country'
),
)
);
public $belongsTo = array(
'Doctor' => array(
'className' => 'Doctor',
"foreignKey" => 'doctor_id'
),
'Office' => array(
'className' => 'Office',
"foreignKey" => 'office_id'
)
);
}
?>
答案 0 :(得分:1)
你不需要在蛋糕中旧 ...只需定义错误所说的变量是未定义的......
在您的控制器中
$office_id = $visitdays = $from_time = $to_time = officename = "";
foreach($schedule as $row)
{
$office_id = $row['DoctorSchedule']['office_id'];
$visitdays = $row['DoctorSchedule']['visitdays'];
$from_time = $row['DoctorSchedule']['from_time'];
$to_time = $row['DoctorSchedule']['to_time'];
}
/* and etc the rest of your code */
顺便说一句......为什么以所有神圣的名义,你有一个从控制器回应的桌子?有没有办法返回一个JSON数组(或xml)并将表的呈现留给调用该动作的url?