tp5.1 无法读取数据库表

浏览:959 发布日期:2019/02/20 分类:ThinkPHP5专区 关键字: tp5.1, 无法读取数据库表
tp5.1 在模型中使用场景验证后,无法读取表,只能获取到表的前缀。 <?php

namespace app\common\model;

use think\facade\Session;
use think\Model;
use think\model\concern\SoftDelete;

class Admin extends Model
{
    //软删除
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;

    // 表名
    protected $name = 'sys_admin';
    //主键
    protected $pk = 'id';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'ctime';
    protected $updateTime = 'utime';
    // 追加属性
    protected $append = [
    ];

    /**
     * 登录
     * @param $data 登录信息
     */
    public function login($data)
    {
        //验证数据
        $validate= new \app\common\validate\Admin();
        if(!$validate->scene('Login')->check($data)){
            return $validate->getError();
        }
        //  查询账户是否存在
        $userinfo=$this->where('username='.$data['username'])->find();
        if(!$userinfo){
            return '账户不存在';
        }
        if(!lay_compare_password($data['password'],$userinfo['password'])){
            return '密码输入错误';
        }
        Session::set('admininfo',$userinfo);
        Session::set('admin_id',$userinfo['id']);
        return 1;
    }




}

附件 微信截图_20190220135150.png ( 35.44 KB 下载:4 次 )

最佳答案
评论( 相关
后面还有条评论,点击查看>>