《ThinkPHP数据自动验证中unique的缺陷》的评论 /tech/1364/ 我的世界 Wed, 10 Apr 2024 03:30:04 +0000 hourly 1 http://wordpress.org/?v=4.6.28 作者:炎藤 /tech/1364/#comment-68307 Thu, 24 Mar 2016 04:41:43 +0000 /?p=1364#comment-68307 不知道你用的是什么版本,不过 3.2.x 有 验证时间 的选项了,可以在 INSERT 的时候做判断就好了

]]>
作者:luobo /tech/1364/#comment-37870 Fri, 15 May 2015 09:03:45 +0000 /?p=1364#comment-37870 相同的问题

]]>
作者:ssss /tech/1364/#comment-20563 Wed, 09 Jul 2014 03:17:27 +0000 /?p=1364#comment-20563 namespace Home\Model;
use Think\Model;
class ClassifyModel extends Model{
protected $_validate = array(
array(‘name’,’require’,’类名称不能为空’),
array(‘name’,’checkNmae’,’类名称已经存在!换一个吧亲’,0,’unique’,3), // 在新增的时候验证name字段是否唯一
);
function checkName($name){
$where=array(“name”=>$name,isself=>0);
$_GET[‘id’] && $where[‘id’]=$_GET[‘id’];
$r=$this->where($where)->find();
if($r){
return $_GET[‘id’]?true:false;
}else{
return true;
}
}
}

]]>
作者:sc_bant /tech/1364/#comment-10624 Wed, 22 May 2013 05:52:19 +0000 /?p=1364#comment-10624 只要表单中有主键id,编辑保存时候,会排除主键id一样的记录,只比较其他记录。即使字段设置为unique,新增编辑都检验,编辑没有任何修改保存,也是更新成功的。

]]>
作者:新手+菜鸟 /tech/1364/#comment-10490 Sun, 28 Apr 2013 14:42:56 +0000 /?p=1364#comment-10490 在代码中动态改变验证规则:$validate=array(验证规则); $modelname->setProperty(‘_validate’,$validate);

]]>
作者:新手+菜鸟 /tech/1364/#comment-10489 Sun, 28 Apr 2013 14:24:01 +0000 /?p=1364#comment-10489 不行,如果对于同一字段还有其他验证,那就不能进行验证了,呵呵。。。白白的。。。。

]]>
作者:新手+菜鸟 /tech/1364/#comment-10488 Sun, 28 Apr 2013 14:19:11 +0000 /?p=1364#comment-10488 非常同意,看过之后,我想到一个方法,就是在input标签中,把name属性值该了(比如原来是admin_id,则可改为aid),这样后台验证时就捕捉不到了,然后通过$_POST[aid]获取,再存入$data[‘admin_id’]中,最后sava($data).

]]>
作者:笨笨 /tech/1364/#comment-1666 Tue, 29 Jun 2010 11:13:52 +0000 /?p=1364#comment-1666 笨笨深夜造访,前来问候。

]]>