yii中的错误消息

时间:2013-09-02 03:03:45

标签: php yii

我遇到了以yii格式放置在每个字段底部的内置错误消息的问题。创建失败后,这些错误消息应该闪烁。

我希望有人可以帮我解决这个问题。 ^^

这是我的代码。

型号:

public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
    array('quantity,unit_cost', 'required','message'=>'Please enter a value for {attribute}.'),
}

控制器:

public function actionCreate() {
    $model=new BaseSiReceivedItem;

    if(isset($_POST['BaseSiReceivedItem']))
    {
        $model->attributes=$_POST['BaseSiReceivedItem'];
        if($model->save()){
        if(Yii::app()->request->isAjaxRequest){
            if($success){
                echo 'success';
                return true;
            }else{
                echo 'fail';
                return true;
            }
        }
        }else{
            $this->redirect(array('BaseIar/createItem'));
        }
    }
}

查看:

    <tr>
        <td><?php echo $form->labelEx($model,'quantity'); ?></td>
        <td>
            <?php echo $form->textField($model,'quantity', array('id'=>'new-base-si-received-item-quantity','disabled'=>'')); ?>
            <?php echo $form->error($model,'quantity'); ?>
        </td>
    </tr>   
    <tr>
        <td><?php echo $form->labelEx($model,'unit_cost'); ?></td>
        <td>
            <?php echo $form->textField($model,'unit_cost',array('size'=>10,'maxlength'=>10,'id'=>'new-base-si-received-item-unit_cost','disabled'=>'')); ?>
            <?php echo $form->error($model,'unit_cost'); ?>
        </td>
    </tr>   

0 个答案:

没有答案