【项目练习】控制器直接操作--登录

控制器

<?php

namespace appadmincontroller;

use thinkController;
use thinkValidate;
use thinkDb;
use thinkModel;

class Index extends controller
{
  //登陆后台
  public function login()
  {

    if (request()->isAjax()) {
      $validate = new Validate([
        'username|用户名'  => 'require',
        'pwd|密码' => 'require'
      ]);
      $data = [
        'username' => input("post.username"),
        'pwd' => input('post.pwd')
      ];
      if (!$validate->check($data)) {
        $this->error($validate->getError());
      }
      $res = Db::name('admin')->where($data)->count();
      if ($res == 1) {
        $this->success('登陆成功', 'admin/home/index');
      } else {
        $this->error('用户名或密码不正确');
      }
    }
    return view();
  }
}

没有多层的束缚,直接操作数据库,但是无法使用软删除等操作

原文地址:https://www.cnblogs.com/xiaozhang666/p/11555815.html