在CakePHP 2.0中加载供应商文件 [英] Loading Vendor Files in CakePHP 2.0

查看:145
本文介绍了在CakePHP 2.0中加载供应商文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将我们的一个项目升级到CakePHP 2.0。不幸的是代码的第一行出现问题,我找不到解决这个问题的解决方案。

I'm currently upgrading one of our projects to CakePHP 2.0. Unfortunately the "first line" of code makes problems, and I can't find a solution to that problem.

在CakePHP 1.3中,我有一个在定义 AppController 类之前的App :: import(Vendor,facebook); 参考文件位于 /app/vendors/facebook/facebook.php 下(并包含 base_facebook.php 文件)。

In CakePHP 1.3 I had an App::import("Vendor", "facebook"); statement right before the AppController class gets defined. The referenced file is located under /app/vendors/facebook/facebook.php (and includes itself the base_facebook.php file).

我尝试了很多不同的方法,根据文件命名和类加载在CakePHP 2.0中包含这个文件: CakePHP 2.0中的文件命名和类加载更改

I tried many different ways to include the file now in CakePHP 2.0 according to the File naming and class loading described here: File naming and class loading changes in CakePHP 2.0

我将路径重命名为 app / Vendor / Facebook / Facebook.php app / Vendor / Facebook / facebook.php ,并尝试以下方法:

I renamed the path to app/Vendor/Facebook/Facebook.php, or app/Vendor/Facebook/facebook.php, and tried following methods:

App::uses("Facebook", "Vendor/Facebook");
App::uses("Facebook", "Facebook");
App::uses("Facebook", "Vendor/Facebook/Facebook.php");
App::uses("Facebook", "Vendor");

有没有人找到一种方法来引用供应商文件?因为延迟加载上面的方法不会触发错误/警告,所以调试这是很烦人...

Has anyone find a way to reference a vendor file yet? Because of the lazy loading the methods above do not fire an error/warning, so it's kind of annoying to debug this...

推荐答案

p>无法使用 App :: uses()在CakePHP中加载供应商,这是因为CakePHP不能指望外部库遵循关于文件夹和文件命名的相同标准。您仍然可以使用 App :: import('Vendor',...),如在框架的1.3版中所做的那样。

Vendors cannot be loaded using App::uses() in CakePHP, this is because CakePHP cannot expect external libraries to follow the same standards regarding folder and file naming. You can still use App::import('Vendor', ...) as you did in version 1.3 of the framework.

现在,使用 App :: import()供应商是一种愚蠢,如果你想。对于 require_once()。这是一个昂贵,冗长和非常愚蠢的包装。

Now, using App::import() for vendors is kind of silly, if you think about it. It is just an expensive, verbose and very silly wrapper for require_once().

人们使用require或require_once作为他们的Vendor库。您可以使用 App :: path('Vendor')或只是 APP获取供应商文件夹的位置。 '供应商'。 DS

In 2.0, we actually encourage people to use require or require_once for their Vendor libraries. You can get the location of the Vendor folder using App::path('Vendor') or just APP . 'Vendor' . DS.

这篇关于在CakePHP 2.0中加载供应商文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆