在注册用户之前先验证年龄,然后使用mvc检查他是否超过一定年龄 [英] validate age before registering a user to check if hes over a certain age using mvc
本文介绍了在注册用户之前先验证年龄,然后使用mvc检查他是否超过一定年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi,我必须开发一种可以记录用户年龄并计算年龄的表格,如果超过18岁,则必须将其带到注册表格中
hi i have to develop a form which takes user age and calculates age and if over 18 procedds to take him to registeration form
我的问题是我是否正在使用zend框架来实现它,因为它不应该与模型进行过多交互并且数据库中没有数据
my question is has i am using zend framework how to implement it when its not supposed to interact with model much and their is no data in database
我如何验证人的年龄
我正在尝试使用此代码
$data = array ( 'dob' => date ( "Y-m-d" ));
$select = $db
->select()
->from('data', array(
'id',
'age' => new Zend_Db_Expr("DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0")))
我可以使用数组吗?请帮助我的朋友这个查询应该如何
can i use an array ? please help me friendshow should be this query
推荐答案
我不太了解您的问题...您是否无法从DOB计算年龄?
I don't quite understand your question... Are you having trouble calculating the age from a DOB?
如果是这样,这应该可以解决您的问题:
If so, this should take care of your problem:
function Age($date = 'now')
{
return intval(substr(date('Ymd') - date('Ymd', strtotime($date)), 0, -4));
}
var_dump(Age('1975-04-25')); // int(36)
if (Age('1975-04-25') >= 18)
{
// proceed to registration
}
这篇关于在注册用户之前先验证年龄,然后使用mvc检查他是否超过一定年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文