上一页 1 ··· 46 47 48 49 50 51 52 53 54 ··· 169 下一页
摘要: 一,配置数据库 .env中数据库的配置: DB_DRIVER=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=mybase DB_USERNAME=root DB_PASSWORD=mypassword DB_CHARSET=utf8mb4 DB_C 阅读全文
posted @ 2025-02-15 11:06 刘宏缔的架构森林 阅读(93) 评论(0) 推荐(0)
摘要: 一,报错信息: SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `news` where `news_id` = 3 limit 1) sql语句从mysql客户端命令可以正常执行,判断问题出在数据库的连接上 阅读全文
posted @ 2025-02-15 11:06 刘宏缔的架构森林 阅读(153) 评论(0) 推荐(0)
摘要: 一,常用的三个作用范围 1, 作用顺序: 实际中间件在工作时,按照注册顺序,路由前处理顺序为由前往后,后处理则由后往前 2,作用范围: 全局中间件: 该中间件以下的路由都可以生效 组路由中间件:对提定的路由组生效 单个路由中间件:对指定的单个路由生效 二,代码例子: 1,中间件代码: package 阅读全文
posted @ 2025-02-12 15:01 刘宏缔的架构森林 阅读(173) 评论(0) 推荐(0)
摘要: 一,代码 1,定义常量的类 Constants/BusinessConstants.php <?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @doc 阅读全文
posted @ 2025-02-09 19:18 刘宏缔的架构森林 阅读(51) 评论(0) 推荐(0)
摘要: 一,安装hyperf/config库 $ composer require hyperf/config config()函数要用到 二,查看.env中的默认设置: 如果.env文件不存在,可以复制.env.example APP_NAME=skeleton APP_ENV=dev DB_DRIVER 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(217) 评论(0) 推荐(0)
摘要: 一,修改composer.json "autoload": { "psr-4": { "App\\": "app/" }, "files": [ "app/Functions.php" ] }, 在files数组中增加我们的函数文件 二,源代码 app/Functions.php <?php use 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(93) 评论(0) 推荐(0)
摘要: 一,定义一个日志group config/autoload/logger.php 'daily' => [ 'handler' => [ 'class' => Monolog\Handler\RotatingFileHandler::class, 'constructor' => [ 'filena 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(84) 评论(0) 推荐(0)
摘要: 一,自定义异常 global/customError.go package global // 自定义错误类型 type CustomError struct { Code int Error error } 二,抛出异常 我们在gorm的自定义log中已经处理过数据库的异常,所以在查询遇到erro 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(129) 评论(0) 推荐(0)
摘要: 一,自定义异常类 Exception/BusinessException.php 我们用官方提供的这个现成的类: <?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyper 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(86) 评论(0) 推荐(0)
摘要: 一,遇到记录不存在时,不记录异常到日志 在建立数据库连接时指定配置 var ( DBLink *gorm.DB ) func SetupDBLink() (error) { var err error //IgnoreRecordNotFoundError: false,默认是false,设置为tr 阅读全文
posted @ 2025-02-09 19:16 刘宏缔的架构森林 阅读(119) 评论(0) 推荐(0)
上一页 1 ··· 46 47 48 49 50 51 52 53 54 ··· 169 下一页