在YII中,如何为模型类中的日期选择器编写规则?
我是新来的在YII中,如何为模型类中的日期选择器编写规则?,yii,Yii,我是新来的YII。我创建了一个包含文本字段的表,创建了模型和crud生成器,为日期创建了文本字段。然后我用datepicker替换了它,但我不知道如何将我的新datepicker与模型连接起来 public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array(
YII
。我创建了一个包含文本字段的表,创建了模型和crud生成器,为日期创建了文本字段。然后我用datepicker替换了它,但我不知道如何将我的新datepicker与模型连接起来
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, gender, age, dob, doj, class,
no_seats, train_name, proof_1, proof_2, proof_3', 'required'),
array('age, class, no_seats', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>20),
array('gender', 'length', 'max'=>6),
array('train_name', 'length', 'max'=>23),
//I created the below statement instead of the previous //one
//created for text field but it is not working
array('dob','date','format'=>Yii::app()->
locale->getDateFormat('medium')),
array('proof_1', 'length', 'max'=>7),
array('proof_2', 'length', 'max'=>8),
array('proof_3', 'length', 'max'=>9),
array('status', 'length', 'max'=>1),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('refid, name, gender, age, dob, doj,
class, no_seats, train_name, proof_1, proof_2,
proof_3, created, lastmodified, status', 'safe', 'on'=>'search'),
);
}
您可以使用如下所示的datepicker小部件来代替您拥有的任何文本输入属性。这将在表单和$\u POST中创建正确的字段,并且可以由模型函数进行操作。请注意,有一个验证器“date”,您可以将其放入模型的规则中。小部件和规则中的日期格式应该相同
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
下面是对验证器的一个很好的总结:
您可以使用如下所示的datepicker小部件来代替您拥有的任何文本输入属性。这将在表单和$\u POST中创建正确的字段,并且可以由模型函数进行操作。请注意,有一个验证器“date”,您可以将其放入模型的规则中。小部件和规则中的日期格式应该相同
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
下面是对验证器的一个很好的总结:
// View
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
// add to Model rules
array('date', 'type', 'type'=>'date', 'dateFormat'=>'dd-MM-yy'),