简体   繁体   English

Yii DATE字段格式表格

[英]Yii DATE field format form

My MySQL have birthdate DATE field for users. 我的MySQL具有用户的birthdate DATE字段。 But in FORMs it show it as one simple text field. 但是在FORM中,它显示为一个简单的文本字段。

<?=echo $form->textField($model,'birthday')?>

There is any way to Yii recognize DATE and format 3 select fields day/month/yeah? 有什么方法可以让Yii识别DATE并格式化3个选择字段day / month / yeah? I used cakephp and it did automatically, helping a lot the development. 我使用cakephp,它是自动完成的,对开发很有帮助。

No there is no automatic way that Yii does this. 没有,Yii不会自动执行此操作。 The easiest way to do this is to add 3 more fields to the model controlling the form, some thing like: 最简单的方法是在控制表单的模型中再添加3个字段,例如:

date_year
date_month
date_day

You can setup the rules to handle the ranges/limits/types in the model. 您可以设置规则以处理模型中的范围/限制/类型。 On the form you can then use those 3 models as test inputs. 然后,您可以在表格上使用这3个模型作为测试输入。 Once the form is submitted (most likely to your controller/action) you can then concatenate the 3 new model attributes to form the string/timestamp for your original model attribute: 提交表单后(最有可能是您的控制者/动作),您可以将3个新的模型属性连接起来,以形成原始模型属性的字符串/时间戳记:

$model->birthdate = $model->date_year."/".$model->date_month."/".$model->date_day

Another alternative is to use jQuery UI datepicker (which is built into Yii by default) 另一种选择是使用jQuery UI datepicker (默认情况下内置到Yii中)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM