下面的模型擴展了CFormModel,我需要提及規則,以使屬性只允許整數。Yii - 如何驗證文本字段僅用於整數
class SearchForm extends CFormModel {
public $min_size;
public $max_size;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules() {
array('min_size, max_size', 'numerical', 'integerOnly'=>true),
);
}
文本字段創建使用 -
<?php echo $form->textField($model,'min_size', array('placeholder' => 'Min Sqft', 'style'=>'width:100px')); ?>
但是,上面的驗證是行不通的。我如何驗證文本字段只允許整數。反正我有可以做驗證
郵控制器代碼。你打電話驗證()? – redGREENblue
嘗試將類型驗證程序也添加到這些字段。 http://www.yiiframework.com/doc/api/1.1/CTypeValidator –