Reputation: 833
Can you guys please help me with this random error? I am using yii and getting the above error. This is the form from my view file:
<?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>
And this is my controller's action:
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
));
}
I am getting the error in the controller on line:
if(isset($_POST['add']))
Thank you for your help.
Upvotes: 1
Views: 2166
Reputation: 19889
Take out the curly bracket after:
$this->redirect(array('disease/index', 'symptomCode'=>$_POST['Symptomhistory']['symptomCode']));
... inside the if(isset($_POST['search']))
statement. Looks like the remnants of a previous version of your foreach loop.
Upvotes: 2