关于thinkphp6.0使用yaconf运行不了程序

浏览:1371 发布日期:2019/12/16 分类:ThinkPHP6专区 关键字: yaconf thinkphp6.0
已安装think-yaconf扩展

common.php
<?php
// 建议在应用的公共函数文件中进行设置
think\facade\Config::setYaconf('thinkphp');

provider.php
<?php
use app\ExceptionHandle;
use app\Request;
// 容器Provider定义文件
return [
'think\Config' => 'think\Yaconf',
'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
];


原来的代码(框架代码):
(/www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Lang.php:69)
public static function __make(Config $config)
{

return new static($config->get('lang'));
}

执行后:
2019/12/16 15:49:49 [error] 28216#0: *1716 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to think\Lang::__make() must be an instance of think\Config, instance of think\Yaconf given in /www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Lang.php:69
Stack trace:
#0 [internal function]: think\Lang::__make(object(think\Yaconf))
#1 /www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Container.php(410): ReflectionMethod->invokeArgs(NULL, Array)
#2 /www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Container.php(259): think\Container->invokeClass('think\\Lang', Array)
#3 /www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Container.php(130): think\Container->make('think\\Lang')
#4 /www/wwwroot/rong/factory/thinkphp6.0/rong/tp6/tp/vendor/topthink/framework/src/think/Container.php(535): think\Container->get('lang')

修改后的代码(使用Yaconf实例):
public static function __make(Yaconf $yaconf)
{

return new static($yaconf->get('lang'));
}

能打印出yaconf的数组出来:
object(think\Lang)#11 (3) { ["config":protected]=> array(8) { ["default_lang"]=> string(5) "zh-cn" ["allow_lang_list"]=> array(1) { [0]=> string(0) "" } ["use_cookie"]=> string(1) "1" ["extend_list"]=> array(1) { [0]=> string(0) "" } ["cookie_var"]=> string(10) "think_lang" ["detect_var"]=> string(4) "lang" ["accept_language"]=> array(1) { ["zh-hans-cn"]=> string(5) "zh-cn" } ["allow_group"]=> string(0) "" } ["lang":"think\Lang":private]=> array(0) { } ["range":"think\Lang":private]=> string(5) "zh-cn" }


但是 还是运行不了 难道是配置错误!!!!!
thinkphp.ini
[app]
;应用地址
app_host=''
;开启debug
app_debug=true
;调试模式
app_trace=true
;应用的命名空间
app_namespace=''
;是否启用路由
with_route=true
;是否启用事件
with_event=true
;自动多应用模式
auto_multi_app=true
;应用映射自动多应用模式有效)
app_map[]=""
;域名绑定(自动多应用模式有效)
domain_bind[]=""
;禁止URL访问的应用列表(自动多应用模式有效)
deny_app_list[]=""
;默认应用
default_app='uinose'
;默认时区
default_timezone='Asia/Shanghai'
;异常页面的模板文件
exception_tmpl='/www/wwwroot/rong/factory/thinkphp6.0/rong/tp/vendor/topthink/framework/src/tpl/think_exception.tpl'
;错误显示信息,非调试模式有效
error_message='页面错误!请稍后再试~'
;显示错误信息
show_error_msg=true
;禁止应用访问
deny_app_list.1="common"
;开启应用快速访问
app_express=true
;应用不存在默认访问 默认应用
default_app='uinose'


[cache]
;默认缓存驱动
default="file"
;缓存连接方式配置
;驱动方式
stores.file.type="File"
;缓存保存目录
stores.file.path=""
;缓存前缀
stores.file.prefix=""
;缓存有效期 0表示永久缓存
stores.file.expire=0
;缓存标签前缀
stores.file.tag_prefix="tag:"
;序列化机制 例如 ['serialize', 'unserialize']
stores.file.serialize[]=""


[console]
;指令定义
commands[]=""


[cookie]
;cookie 保存时间
expire=0
;cookie 保存路径
path='/'
;cookie 有效域名
domain=''
;cookie 启用安全传输
secure=false
;httponly设置
httponly=false
;是否使用 setcookie
setcookie=true


[database]
;默认使用的数据库连接配置
default="mysql"
;自定义时间查询规则
time_query_rule[]=""
;自动写入时间戳字段
;true为自动识别类型 false关闭
;字符串则明确指定时间字段类型 支持 int timestamp datetime date
auto_timestamp=true
;时间字段取出后的默认时间格式
datetime_format='Y-m-d H:i:s'
;数据库连接配置信息
;数据库类型
connections.mysql.type="mysql"
;服务器地址
connections.mysql.hostname="127.0.0.1"
;数据库名
connections.mysql.database=""
;用户名
connections.mysql.username="root"
;密码
connections.mysql.password=""
;端口
connections.mysql.hostport="3306"
;数据库连接参数
connections.mysql.params[]=""
;数据库编码默认采用utf8
connections.mysql.charset="utf8"
;数据库表前缀
connections.mysql.prefix=""
;数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
connections.mysql.deploy=0
;数据库读写是否分离 主从式有效
connections.mysql.rw_separate=false
;读写分离后 主服务器数量
connections.mysql.master_num=1
;指定从服务器序号
connections.mysql.slave_no=""
;是否严格检查字段是否存在
connections.mysql.fields_strict=true
;是否需要断线重连
connections.mysql.break_reconnect=false
;监听SQL
connections.mysql.trigger_sql=true
;开启字段缓存
connections.mysql.fields_cache=false
;字段缓存路径
connections.mysql.schema_cache_path='/www/wwwroot/rong/factory/thinkphp6.0/rong/tp/runtime/schema'.DIRECTORY_SEPARATOR

[domain]
;域名绑定应用
;blog子域名绑定到blog应用
domain_bind.blog='blog'
;完整域名绑定
domain_bind['shop.tp.com']='shop'
;二级泛域名绑定到home应用
domain_bind.*='home'


[filesystem]
;默认磁盘
default="local"
;磁盘列表
disks.local.type="local"
disks.local.root="/www/wwwroot/rong/factory/thinkphp6.0/rong/tp/runtime/storage"
;磁盘类型
disks.public.type="local"
;磁盘路径
disks.public.type='/www/wwwroot/rong/factory/thinkphp6.0/rong/tp/public/storage'
;磁盘路径对应的外部URL路径
disks.public.url="/storage"
;可见性
disks.public.visibility="public"


[lang]
;默认语言
default_lang="zh-cn"
;允许的语言列表
allow_lang_list[]=""
;多语言自动侦测变量名
detect_var= 'lang'
;是否使用Cookie记录
use_cookie=true
;多语言cookie变量
cookie_var="think_lang"
;扩展语言包
extend_list[]=""
;Accept-Language转义为对应语言包名称
accept_language.zh-hans-cn='zh-cn'
;是否支持语言分组
allow_group=false


[log]
;默认日志记录通道
default="file"
;日志记录级别
level[]=""
;日志类型记录的通道 ['error'='email',...]
type_channel[]=""
;关闭全局日志写入
close=false
;全局日志处理 支持闭包
processor=null
;日志通道列表
;日志记录方式
channels.file.type="File"
;日志保存目录
channels.file.path= ''
;单文件日志写入
channels.file.single=false
;独立日志级别
channels.file.apart_level[]=""
;最大日志文件数量
channels.file.max_files=0
;使用JSON格式记录
channels.file.json=false
;日志处理
channels.file.processor= null
;关闭通道日志写入
channels.file.close= false
;日志输出格式化
channels.file.format= '[%s][%s] %s'
;是否实时写入
channels.file.realtime_write= false


[middleware]
;别名或分组
alias[]=""
;优先级设置,此数组中的中间件会按照数组中的顺序优先执行
priority[]=""


[route]
;pathinfo分隔符
pathinfo_depr = '/'
;URL伪静态后缀
url_html_suffix= 'html'
;URL普通方式参数 用于自动生成
url_common_param= true
;是否开启路由延迟解析
url_lazy_route= false
;是否强制使用路由
url_route_must= true
;合并路由规则
route_rule_merge= false
;路由是否完全匹配
route_complete_match= true
;是否开启路由缓存
route_check_cache= false
;路由缓存连接参数
route_cache_option[]=""
;路由缓存Key
route_check_cache_key= ''
;访问控制器层名称
controller_layer= 'controller'
;空控制器名
empty_controller= 'Error'
;是否使用控制器后缀
controller_suffix= false
;默认的路由变量规则
default_route_pattern= '[\w\.]+'
;是否开启请求缓存 true自动缓存 支持设置请求缓存规则
request_cache= false
;请求缓存有效期
request_cache_expire = null
;全局请求缓存排除规则
request_cache_except[] =""
;默认控制器名
default_controller= 'Index'
;默认操作名
default_action= 'index'
;操作方法后缀
action_suffix= ''
;默认JSONP格式返回的处理方法
default_jsonp_handler= 'jsonpReturn'
;默认JSONP处理方法
var_jsonp_handler= 'callback'



[session]
;session name
name= 'PHPSESSID'
;SESSION_ID的提交变量,解决flash上传跨域
var_session_id= ''
;驱动方式 支持file cache
type= 'file'
;存储连接标识 当type使用cache的时候有效
store = null
;过期时间
expire= 1440
;前缀
prefix = ''[trace];内置Html 支持扩展
type= 'Html'
;读取的日志通道名
channel= ''


[view]
;模板引擎类型
type= 'Think'
;默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
auto_rule= 1
;模板目录名
view_dir_name= 'view'
;模板路径 ./template/
view_path= ''
;模板后缀
view_suffix= 'html'
;模板文件名分隔符 DIRECTORY_SEPARATOR
view_depr= '_'
;模板引擎普通标签开始标记
tpl_begin = '{'
;模板引擎普通标签结束标记
tpl_end = '}'
;标签库标签开始标记
taglib_begin= '{'
;标签库标签结束标记
taglib_end = '}'
;cdn文件路径
cdn_domain = ''
;插件目录
static_plug='static/plug'
;代码目录
static_code='static/code'

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