Yii::$service无法获取session,fecshoplang等子服务信息

问题咨询 · RobinSC · 于 5年前 发布 · 1789 次阅读

服务器为阿里云 操作系统为CentOS7 通过composer安装好fecshop后,按照http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-about-config.html 进行完初始配置 通过浏览器访问前端appfront,appadmin等模块提示子服务无法获取 报错截图

尝试打印Yii::$service信息,结果为一个Application的对象,包含多个子模块,尝试访问Yii::$service->admin可以打印出各参数 截图 但当打印Yii::$service->adminUser,Yii::$service->session等信息时都显示找不到对应子模块,但Yii::$service中是有相关配置的。 请问有没有朋友遇到过相同问题,还请不吝赐教。

共收到 2 条回复 问题提问
Fecmall#15年前 0 个赞

session配置:@fecshop/config/services/Session.php

1.在@app/web/index.php可以看到

new fecshop\services\Application($config['services']);

也就是执行:https://github.com/fecshop/yii2_fecshop/blob/master/services/Application.php#L66 进行初始化操作

1.1Yii::$service 就是类:https://github.com/fecshop/yii2_fecshop/blob/master/services/Application.php

1.2将 $config['services'] 赋值给 $this->childService

2.下面,当访问 Yii::$service->session的时候,因为没有这个属性,就会执行魔术方法

/**
     * 魔术方法,当调用一个属性,对象不存在的时候就会执行该方法,然后
     * 根据构造方法注入的配置,实例化service对象。
     * @var string $serviceName service name
     * @return \fecshop\services\Service
     * @throws \yii\base\InvalidConfigException if the service does not exist or the service is disabled
     */
    public function __get($serviceName)
    {
        return $this->getChildService($serviceName);
    }

然后执行 getChildService()方法,然后就会到配置中找,session的配置文件是:https://github.com/fecshop/yii2_fecshop/blob/master/config/services/Session.php

找到配置就会实例化,最终的结果就是单例模式的session对象

这个就是整个流程,自己打印排查一下原因吧

RobinSC#25年前 0 个赞

谢谢回复,我再仔细阅读一下配置文档吧

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics