model:
public $bPoint;
public $bCard;
public function tableName()
{
return 'carfree';
}
public function rules()
{
return array(
array('openid, carmark,bCard realname, telephone, bTime, bArea', 'required'),
array('flg, service, quality,card_id', 'numerical', 'integerOnly'=>true),
array('openid, carmark, realname', 'length', 'max'=>50),
array('telephone, cTime, qTime, sTime, wTime, pTime', 'length', 'max'=>13),
array('bFlg, quser, suser, wuser', 'length', 'max'=>20),
array('bArea', 'length', 'max'=>200),
array('carmark','match','pattern'=>'/^[\x{4e00}-\x{9fa5}]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[\x{4e00}-\x{9fa5}A-Za-z0-9]{1}$/u'),
array('bCard','checkbank'),
array('id, openid, carmark, realname, telephone, bTime, bFlg, bArea,bCity,bPoint, cTime, qTime, flg, sTime, wTime, service, quality, pTime, quser, suser, wuser, card_id,bCard', 'safe', 'on'=>'search'),
);
}
public function checkbank($attribute,$params)
{
$card = $this->bCard;
if($card != '222')
{
$this->addError('bCard','银行卡号有误');
}
}
views
<?php $form = $this->beginWidget('CActiveForm',array('id'=>'detailForm','enableAjaxValidation'=>false,'enableClientValidation'=>true,'clientOptions' => array('validateOnSubmit'=>true))); ?>
<?php if($flg == 2):?>
<div class="tpy-road-list clearfix">
<div class="tpy-road-lb left"><?php echo $form->label($model,'bCard');?></div>
<div class="tpy-road-input left">
<?php echo $form->textField($model,'bCard',array(
'class'=>'road-input-txt','placeholder'=>'请输入银行卡号'));?>
<?php echo $form->error($model,'bCard');?>
</div>
</div>
<?php endif;?>
<div class="tpy-road-list clearfix">
<div class="tpy-road-lb left"><?php echo $form->label($model,'carmark');?></div>
<div class="tpy-road-input left">
<?php echo $form->textField($model,'carmark',array(
'class'=>'road-input-txt','placeholder'=>'请输入车牌号','value'=>$user['carmark']));?>
<?php echo $form->error($model,'carmark');?>
</div>
</div>
controller
$flg = $_REQUEST['flg'];
$model = new CarFree;
$model->bCity = 4;
$openid = Yii::app()->session['openID'];
if($openid == '')
{
echo '您的授权已失效,请重新授权';
}else{
$user = Publicuser::model()->findByAttributes(array('openid'=>$openid));
}
if($user['realname'] == '微信用户' || $user['realname'] == '微信客户')
{
$user['realname'] = '';
}
if(isset($_POST['Carfree']))
{
$model->attributes=$_POST['Carfree'];
if($model->validate())
{
echo '222';
}
}
小弟实在不知model 里的验证方法有何问题,但是一点提交就报错
属性 “Carfree.bCard realname” 未被定义.
rules里的bCard realname
是什么鬼?
是指bCard
,realname
?