V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
444683462
V2EX  ›  问与答

thinkphp 自动验证问题

  •  
  •   444683462 · 2015-03-16 10:17:10 +08:00 · 1777 次点击
    这是一个创建于 3331 天前的主题,其中的信息可能已经有所发展或是发生改变。

    html

    <input name="name" type="text" class="input-large"/>
    model

    /自动映射/
    protected $_map = array(
    //左边的是表单=>右边是数据库字段
    'name' =>'department_name',
    );

    /*自动验证*/
    

    protected $_validate = array(
    array('department_name','require','部门名称不能为空'),
    );
    controller

    $Department=D('Department');
        //新增数据的流程
            if(I('post.name')){
    
                if (!$Department->create()){ // 创建数据对象
                    // 如果创建失败 表示验证没有通过 输出错误提示信息
                    exit($Department->getError());
                }else{
                    // 验证通过 写入新增数据
                 /*   $Department->create();*/
                    $Department->add();
    
                    if($Department>0){
                        $this->redirect('createDepartment',array('add' =>1));
                    }else{
                        $this->error("数据新增失败");
                    }
                }
    
        }
    

    thinkphp

    4 条回复    2015-03-16 11:32:44 +08:00
    444683462
        1
    444683462  
    OP
       2015-03-16 10:28:19 +08:00
    补充一下问题?:自动验证无法通过。点击提交就刷新了一下页面,没有做任何验证。
    br00k
        2
    br00k  
       2015-03-16 10:53:30 +08:00
    debug一下会死?
    woshicixide
        3
    woshicixide  
       2015-03-16 11:28:38 +08:00
    tp3.0里面还有个表单令牌的东东,看看是不是这个引起的
    xjx0524
        4
    xjx0524  
       2015-03-16 11:32:44 +08:00
    你可以看看create()的代码,debug一下是否执行了你那条验证规则
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5719 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:06 · PVG 11:06 · LAX 20:06 · JFK 23:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.