如何将所有 Stripe 类 自动导入 CakePHP
How to auto import all Stripe classes into CakePHP
如何将所有必要的 类 从 Stripe PHP SDK (2.1.0) 导入 CakePHP (2.6.1)?
我已经为 Stripe 添加了一个子模块并将其克隆到 app/Vendor/Stripe
我的代码如下所示:
<?php
App::uses('Stripe', 'Vendor/Stripe/lib');
// Secret API Key for Stripe
\Stripe\Stripe::setApiKey('sk_test_xxxxxxxxxxxxxxxxxxx');
class BillingController extends AppController {
// My methods
}
?>
我得到:
Fatal Error
Error: Class 'Stripe\Stripe' not found
File: /Projects/Web/admin.example.io/app/Controller/BillingController.php
Line: 6
您应该在使用 vendor 时使用 import()
,而不是 uses()
喜欢
App::import('Vendor', 'Stripe', array('file' => 'Stripe' . DS .'lib' . DS . 'Stripe.php'));
此处 DS 对于 /
是常数。
您应该遵循 cakephp 命名约定,例如 import() Must
在使用 Vendor 包时使用。在使用控制器等其他 类 时,您可以使用 uses() 但在您的情况下不能使用此处。
更新:
现在 步骤,您需要按照它更具体地针对您的问题进行操作:
1.Install 使用作曲家。
2.Now 使用
导入安装 package/vendor
App::import('Vendor', 'autoload', array('file' => 'Stripe' . DS .'vendor' . DS . 'autoload.php'));
您应该包含 init.php 文件。
压缩文件的目录结构是这样的:
stripe-php
- libs/
- data/
- test/
- init.php
不要在 libs 文件夹中包含 PHP 文件,只需包含 init.php.
如何将所有必要的 类 从 Stripe PHP SDK (2.1.0) 导入 CakePHP (2.6.1)?
我已经为 Stripe 添加了一个子模块并将其克隆到 app/Vendor/Stripe
我的代码如下所示:
<?php
App::uses('Stripe', 'Vendor/Stripe/lib');
// Secret API Key for Stripe
\Stripe\Stripe::setApiKey('sk_test_xxxxxxxxxxxxxxxxxxx');
class BillingController extends AppController {
// My methods
}
?>
我得到:
Fatal Error
Error: Class 'Stripe\Stripe' not found
File: /Projects/Web/admin.example.io/app/Controller/BillingController.php
Line: 6
您应该在使用 vendor 时使用 import()
,而不是 uses()
喜欢
App::import('Vendor', 'Stripe', array('file' => 'Stripe' . DS .'lib' . DS . 'Stripe.php'));
此处 DS 对于 /
是常数。
您应该遵循 cakephp 命名约定,例如 import() Must
在使用 Vendor 包时使用。在使用控制器等其他 类 时,您可以使用 uses() 但在您的情况下不能使用此处。
更新:
现在 步骤,您需要按照它更具体地针对您的问题进行操作:
1.Install 使用作曲家。
2.Now 使用
导入安装 package/vendorApp::import('Vendor', 'autoload', array('file' => 'Stripe' . DS .'vendor' . DS . 'autoload.php'));
您应该包含 init.php 文件。
压缩文件的目录结构是这样的:
stripe-php
- libs/
- data/
- test/
- init.php
不要在 libs 文件夹中包含 PHP 文件,只需包含 init.php.