加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 我应该使用App :: import(‘Model’,…)还是ClassRegistr

发布时间:2020-12-13 13:38:30 所属栏目:PHP教程 来源:网络整理
导读:由于其他答案( like this),我只想澄清CakePHP 1.3中应该使用的内容. 具体来说,我有一种情况要求模型依赖于另一个,所以从该模型中的方法我想加载另一个,用信息做一些事情,等等. documentation for the App Class说: In previous versions there were differe
由于其他答案( like this),我只想澄清CakePHP 1.3中应该使用的内容.

具体来说,我有一种情况要求模型依赖于另一个,所以从该模型中的方法我想加载另一个,用信息做一些事情,等等.

documentation for the App Class说:

In previous versions there were different functions for loading a needed class based on the type of class you wanted to load. These functions have been deprecated,all class and library loading should be done through App::import() now.

我假设这涵盖了ClassRegistry等的使用,但我只是希望它清楚,并且确定:

我应该使用App :: import(‘Model’,…)来利用另一个模型或其他模型吗?如果别的什么,什么?

看来,即使是2008年以来的两年,最好的方法是使用ClassRegistry :: init(),尽管引用了文档.

这在特定类/方法的实际API /文档中很明显.

App::import()

Finds classes based on $name or specific file(s) to search. Calling App::import() will not construct any classes contained in the files. It will only find and require() the file.

ClassRegistry::init()

Loads a class,registers the object in the registry and returns instance of the object.

Examples Simple Use: Get a Post model instance ClassRegistry::init(‘Post’);

正如您所看到的,即使API文档也指出了使用ClassRegistry加载模型,为您实例化它们的示例,而不是App :: import(它做得少得多),尽管CakePHP“Book”文档中的措辞已经改变了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读