在 CakePHP 2.0 中加载供应商文件

Loading Vendor Files in CakePHP 2.0(在 CakePHP 2.0 中加载供应商文件)
本文介绍了在 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...

推荐答案

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

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().

在 2.0 中,我们实际上鼓励人们为他们的供应商库使用 require 或 require_once.您可以使用 App::path('Vendor') 或仅使用 APP 来获取 Vendor 文件夹的位置.'小贩' .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 中加载供应商文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)