PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ThinkPhp教程 > 正文

    ThinkPhp 自动验证 为什么会出现 “非法数据对象!”

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:自动验证 为什么会出现 非法数据对象!<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Contr...
    自动验证 为什么会出现 “非法数据对象!”
    <?php
    namespace Home\Controller;
    use Think\Controller;
    class IndexController extends Controller {
    public function index(){
    $User = D("title");
    // 实例化User对象
    if (!$User->create()){

    // 创建数据对象
    // 如果创建失败 表示验证没有通过 输出错误提示信息
    exit($User->getError());
    }else{

    // 验证通过 写入新增数据
    $User->add();
    }

    //$this->display();
    }
    }

    MODEL的:
    <?php
    namespace Home\Model;
    use Think\Model;
    class TitleModel extends Model {

    protected $_validate =
    array(

    array('title','require','验证码必须!'),

    );
    }

    view:
    <form action="{:U('Index/index')}" method="post" />
    TITLE:<input type="text" name="title" /><br/>
    <input type="submit" name="submit" value="提交" />
    </form>
    </div>

    解决方法:

    1.你打印下你post的值,应该是你没post过去值

    2.我也遇到过,而且验证码老是不对

    3.POST 里面传值有其他字段
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-83-1048-1.html
    相关热词搜索: