thinkphp 自动验证问题

2015-03-16 10:17:10 +08:00
 444683462

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

1781 次点击
所在节点    问与答
4 条回复
444683462
2015-03-16 10:28:19 +08:00
补充一下问题?:自动验证无法通过。点击提交就刷新了一下页面,没有做任何验证。
br00k
2015-03-16 10:53:30 +08:00
debug一下会死?
woshicixide
2015-03-16 11:28:38 +08:00
tp3.0里面还有个表单令牌的东东,看看是不是这个引起的
xjx0524
2015-03-16 11:32:44 +08:00
你可以看看create()的代码,debug一下是否执行了你那条验证规则

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/177189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX