它需要从Config / file_upload_settings.PHP导入FileUploadSettings类,并从vendor / upload.PHP导入Uploader类.可以使用require_once函数完成,但我确定有一个CakePHP方法可以实现.
api文档说the following主题:
All classes that were loaded in the past using
App::import(‘Core’,$class)will need to be loaded usingApp::uses()referring to the correct package. This change has provided large performance gains to the framework.
- The method no longer looks for classes recursively,it strictly uses
the values for the paths defined inApp::build()- It will not be able to load
App::import('Component','Component')useApp::uses('Component','Controller');.- Using
App::import('Lib','CoreClass');to load core classes is no longer possible. Importing a non-existent file,supplying a wrong type or package name,ornullvalues for$nameand$fileparameters will result in a false return value.App::import('Core','CoreClass')is no longer supported,useApp::uses()instead and let the class autoloading do the rest.- Loading vendor files does not look recursively in the vendors folder,it will also not convert the file to underscored anymore as it did in the past.
迁移指南还有some things to say关于App:uses(),并且是将2.0的最佳实践与1.3及更低版本的较旧方法进行比较的良好起点.
This related question处理在Cake 2.0中加载供应商文件,我无法验证JoséLorenzo的声明:App:import()是require_once()的“傻包装”,也不是包含文件的首选方式的声明.我可以找到的唯一的参考是在Coding Standards的蛋糕贡献者,即开发人员为Cake的核心做贡献,而不是构建在框架上的应用程序.
编辑
假设您要导入Twitter OAuth library,驻留在vendor / twitter中,主要类文件是vendor / twitter / twitteroauth / twitteroauth.PHP中的twitteroauth.PHP:
App::import('vendor','twitteroauth',array('file' => 'twitter'.DS.'twitteroauth'.DS.'twitteroauth.PHP'));