简体   繁体   English

CakePHP ::使用表单助手将默认日期添加到DOB字段中吗?

[英]CakePHP :: Adding a default date into a DOB field with the form helper?

This might be a very simple answer but all my research so far is not coming up with an answer! 这可能是一个非常简单的答案,但是到目前为止,我的所有研究都还没有得出答案!

I am using CakePHP 2.4 I have set up a Form using the CakePHP helper, with a dob field within the list, 我正在使用CakePHP 2.4,我已经使用CakePHP帮助程序设置了一个表单,并且列表中有一个dob字段,

 $DOBOps = array('label' => 'D.O.B','div' => false, 'type' => 'date',
           'dateFormat' => 'DMY','maxYear' => date('Y') - 100,
           'minYear' => date('Y'), 'default' => $UserDOB);

 $this->Form->input('dobraw', $DOBOps);

Now its called dobraw so it does not list in my $this->data as dob becuase I want to convert it 1st. 现在称为dobraw,因此它不会在$this->data列出为dob,因为我想将其转换为1。 So I take the day, month and year and use PHP to convert it to a simple timestamp, which I then set as the dob using $this->request->data . 因此,我采用了年,月和日,并使用PHP将其转换为简单的时间戳,然后使用$this->request->data将其设置为dob。

This all works, my code converts it fine and saves the data into the database, but when I go back to the user profile / settings page I want it to update the form with the data saved into the database. 所有这些都有效,我的代码将其很好地转换并将数据保存到数据库中,但是当我返回到用户配置文件/设置页面时,我希望它使用保存到数据库中的数据来更新表单。

I have tried, adding a default tag to it but it does not work, I have also converted back to dd-mm-yyyy format, so $UserDOB holds a data not a timestamp. 我已经尝试过,向其添加默认标记,但是它不起作用,我还转换回了dd-mm-yyyy格式,因此$UserDOB保留的数据不是时间戳。

Thanks, 谢谢,

I have solved it, I thought that because it was loading dd-mm-yyyy. 我已经解决了,我认为是因为它正在加载dd-mm-yyyy。 I would have to set the data I am giving it to the same format - but I seems to work when I get it the pure timestamp. 我必须将提供的数据设置为相同的格式-但当我获得纯时间戳记时,我似乎可以正常工作。

If there is a better way of doing it please let me know. 如果有更好的方法,请告诉我。

Thanks. 谢谢。

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

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