美文网首页
2019-12-26 thinkphp5

2019-12-26 thinkphp5

作者: 月圆星繁 | 来源:发表于2019-12-26 18:17 被阅读0次

    migration的安装

    thinkphp5 migration 默认是没有安装的,需要用composer 安装下。
    composer require topthink/think-migration

    我的composer 不是全局安装的,omg。
    windows下安装的把composer.phar加入到环境变量的path中就可以了。

    composer 安装migration时报错 Your requirements could not be resolved to an installable set of packages.

    经查询,是我的thinkphp5 framework不是6.0,所有安装migration需要选满足框架的版本,就向下选了v2.0.3,安装时候的命令需要带上版本号,
    composer require topthink/think-migration "v2.0.3"

    使用方法:

    https://www.kancloud.cn/manual/thinkphp5/215850

    Request的不同

    引入不同使用不同

    1. use think\facade\Request;
    <?php
    namespace app\admin\controller;
    
    use think\Controller;
    use think\facade\Request;
    use \app\admin\model\Admin;
    
    class Login extends Controller
    {
        /**
         * 登录
         * @return \think\Response
         */
        public function signin(Request $request)
        {
            if($request->isGet()){
                return view('signin',['title'=>'*登录*']);
            }
            if($request->isPost()){
                // todo 
            }
        }
    
    1. use think\Request;
    <?php
    namespace app\admin\controller;
    
    use think\Controller;
    use think\Request;
    use \app\admin\model\Admin;
    
    class Login extends Controller
    {
        /**
         * 登录
         * @return \think\Response
         */
        public function signin()
        {
            if(Request::isGet()){
                return view('signin',['title'=>'*登录*']);
            }
            if(Request::isPost()){
                // todo 
            }
        }
    

    命令行

    使用php think 可以展示出可用的命令,这laravel的php artisan大致差不多的感觉。

    验证器

    可以定义不同的验证场景,为每个想要验证的方法定义一个场景。
    Validate:

    /**
         * 定义验证场景
         */
        protected $scene = [
            'signin' => ['username', 'password'],
        ];
    

    验证:

    $result = $this->validate($data, 'Admin.signin');
    if(true !== $result) {
         $this->error($result);
    }
    

    相关文章

      网友评论

          本文标题:2019-12-26 thinkphp5

          本文链接:https://www.haomeiwen.com/subject/usgkoctx.html