具体来说,我有一种情况要求模型依赖于另一个,所以从该模型中的方法我想加载另一个,用信息做一些事情,等等.
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’,…)来利用另一个模型或其他模型吗?如果别的什么,什么?
这在特定类/方法的实际API /文档中很明显.
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.
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”文档中的措辞已经改变了.