简体   繁体   English

Yii解析错误:语法错误,意外的'if'(T_IF),期望的函数(T_FUNCTION)

[英]Yii Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)

Can you guys please help me with this random error? 你们能帮我解决这个随机错误吗? I am using yii and getting the above error. 我正在使用yii并收到上述错误。 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. 谢谢您的帮助。

Take out the curly bracket after: 取出花括号后:

$this->redirect(array('disease/index', 'symptomCode'=>$_POST['Symptomhistory']['symptomCode']));

... inside the if(isset($_POST['search'])) statement. ...在if(isset($_POST['search']))语句中。 Looks like the remnants of a previous version of your foreach loop. 看起来像您的foreach循环的先前版本的残迹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP,解析错误:语法错误,意外的T_IF,预期为T_FUNCTION - PHP, Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION 解析错误:语法错误,意外\\&#39;?&gt; \\&#39;,期待函数(T_FUNCTION) - Parse error: syntax error, unexpected \'?>\', expecting function (T_FUNCTION) 语法错误,意外的T_FUNCTION,预期为&#39;)&#39; - syntax error, unexpected T_FUNCTION, expecting ')' Wordpress-解析错误:语法错误,意外的“函数”(T_FUNCTION),期望的标识符(T_STRING) - Wordpress - Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) php解析错误:语法错误,意外的T_STRING,在构造上需要T_FUNCTION - php Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION on construct 解析错误:语法错误,意外的“函数”(T_FUNCTION),预计在第319行 - Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting on line 319 PHP解析错误:语法错误,意外的T_STRING,预期的T_FUNCTION - PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION 解析错误:语法错误,意外的T_VARIABLE,预期为T_FUNCTION - Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION PHP版本5.2.14 /解析错误:语法错误,意外的T_FUNCTION,期望&#39;)&#39; - PHP Version 5.2.14 / Parse error: syntax error, unexpected T_FUNCTION, expecting ')' 解析错误:语法错误,意外的&#39;=&#39;,期望在第33行的DB_driver.php中出现T_FUNCTION - Parse error: syntax error, unexpected '=', expecting T_FUNCTION in DB_driver.php on line 33
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM