Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tp6.0,DbManager容器重新创建新实例后,Model内存储的没有更新 #2927

Open
aLoNeIT opened this issue Aug 11, 2023 · 3 comments
Labels

Comments

@aLoNeIT
Copy link

aLoNeIT commented Aug 11, 2023

  • 查阅代码,发现ModelService中启动时使用Model::setDb($db)设置了一次db实例,然后在DbManager中的modelMaker中也使用Model::setDb($this)设置了一次db,但是在继承他的think\Db类中,modelMaker成了空方法,导致就算重新创建了容器中的db实例,也无法更新Model中存储的静态变量$db,从而导致在cli模式下运行时手动重新创建db却仍然出问题的情况。
  • 其次,在App.php文件中,发现db和think\DbManager都对应Db类,cache和think\CacheManager都对应Cache类,log和think\LogManager都对应Log类
  • 在facade文件中,Cache标识是cache,Log标识是log,Db标识却又成了think\DbManager

以上问题,麻烦确认下是否存在不合理之处,尤其是第一点!

@aLoNeIT
Copy link
Author

aLoNeIT commented Aug 11, 2023

另外补充下,能否各个组件内部不要保存容器对象到当前类成员中,而是每次实时从容器中获取呢?

@aLoNeIT
Copy link
Author

aLoNeIT commented Aug 11, 2023

各个类里面的setCache能否改成设置缓存的驱动名称呢?然后各个类内部通过$this->app->cache->store($this->cacheDriver)来实时获取?
各个类里面的setDb更是可以取消了,可以直接内部用$this->app->db来直接获取了,甚至于setCache也可以这样来做。

@big-dream big-dream added the ORM label Jun 27, 2024
@liu21st
Copy link
Member

liu21st commented Aug 13, 2024

主要是因为think-orm库是设计为可以独立使用 不依赖TP框架的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants