你能帮我解决这个随机错误吗?我正在使用yii并得到上述错误。这是我的视图文件中的表单:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'symptomhistory-form',
'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->errorSummary($model); ?>
<br/>
<?php echo $form->textField($model,'symptomCode', array('id'=>'symptomToBeSearchedCode')); ?>
<?php echo $form->error($model,'symptomCode'); ?>
<br/>
<?php echo $form->textField($model,'symptomTitle', array('id'=>'symptomToBeSearchedTitle')); ?>
<?php echo $form->error($model,'symptomTitle'); ?>
<br/>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'model'=>$model,
'attribute'=>'dateSymptomFirstSeen',
'id'=>'dateSymptomSeen',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd', //date format set to be compatible with database
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
)); ?>
<?php echo CHtml::submitButton('Search Symptom(s)', array('name'=>'search')); ?>
<?php echo CHtml::submitButton('Add Another Symptom to Search', array('id'=>'addSymptom', 'name'=>'add')); ?>
</div>
这是我的控制者的行动:
public function actionSearch()
{
//initial model creation
if(!isset($model))
{
//initiliaze varaiable to keep count of active records to be created
$modelCounter=0;
//initialize empty model array for SymptomHistory ActiveRecords
$model=array();
//initialize empty array for Symptom titles
$symptomTitles=array();
$model[$modelCounter]=new Symptomhistory;
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['search']))
{
//populate symptom search model attributes with user id, current date, and form input
$model[$modelCounter]->setAttributes(array(
'user_id'=>Yii::app()->user->id,
'dateSearched'=>date('Y-m-d'),
'symptomCode'=>$_POST['Symptomhistory']['symptomCode'],
'dateSymptomFirstSeen'=>$_POST['Symptomhistory']['dateSymptomFirstSeen'],
'symptomTitle'=>$_POST['Symptomhistory']['symptomTitle'],
));
//save models
foreach($model as $symptomHistoryModel)
{
$symptomHistoryModel->save();
}
$this->redirect(array('disease/index', 'symptomCode'=>$_POST['Symptomhistory']['symptomCode']));
}
}
if(isset($_POST['add']))
{
//populate symptom search model attributes with user id, current date, and form input
$model[$modelCounter]->setAttributes(array(
'user_id'=>Yii::app()->user->id,
'dateSearched'=>date('Y-m-d'),
'symptomCode'=>$_POST['Symptomhistory']['symptomCode'],
'dateSymptomFirstSeen'=>$_POST['Symptomhistory']['dateSymptomFirstSeen'],
'symptomTitle'=>$_POST['Symptomhistory']['symptomTitle'],
));
//increase counter
$modelCounter++;
$model[$modelCounter]=new Symptomhistory;
$this->refresh();
}
$this->render('search',array(
'model'=>$model[$modelCounter],'symptomTitles'=>$symptomTitles
));
}
我在线控制器中收到错误:
if(isset($_POST['add']))
感谢您的帮助。
答案 0 :(得分:2)
取出后面的花括号:
$this->redirect(array('disease/index', 'symptomCode'=>$_POST['Symptomhistory']['symptomCode']));
...在if(isset($_POST['search']))
语句中。看起来像是foreach循环的先前版本的残余。