Laravel 4 使用供应商类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15398087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 using vendor classes
提问by Jjames
I have installed Laravel 4 after using 3, love it. I used to be able to use the Zend framework as such:
我在使用 3 后安装了 Laravel 4,喜欢它。我曾经能够像这样使用 Zend 框架:
$yt = new Zend_Gdata_YouTube();
for instance
例如
I have used composer to install Zend and everything is installed in the Vendor folder..
我已经使用 composer 安装 Zend,所有东西都安装在 Vendor 文件夹中。
Problem:
问题:
How to address the individual classes i.e. Zend Gdata etc.
如何处理单个类,即 Zend Gdata 等。
I can't find any documentation on calling classes from a vendor in L4. Any help is appreciated.
我在 L4 中找不到任何关于从供应商调用类的文档。任何帮助表示赞赏。
回答by JasonMortonNZ
Take a look at your vendor\composer\autoload_classmap.php file. In there you will find a list of all vendor classes that are being autoloaded. I think all classes will have to be called using their full namespaced name.
查看您的 vendor\composer\autoload_classmap.php 文件。在那里,您会找到正在自动加载的所有供应商类的列表。我认为所有类都必须使用它们的完整命名空间名称来调用。
E.g.
例如
I'm using Zizaco's Entrust package. This is what it looks like in the vendor\composer\autoload_classmap.php file.
我正在使用 Zizaco 的 Entrust 包。这就是 vendor\composer\autoload_classmap.php 文件中的样子。
'Zizaco\Entrust\Entrust' => $vendorDir . /zizaco/entrust/src/Zizaco/Entrust/Entrust.php',
If I wanted to access the Entrust.php class I have to call
如果我想访问 Entrust.php 类,我必须调用
$en = new Zizaco\Entrust\Entrust();
Alternatively you could alias certain classes in your app\config\app.php file.
或者,您可以在 app\config\app.php 文件中为某些类设置别名。
E.g.
例如
'Ent' => 'Zizaco\Entrust\Entrust'
In your case you'll need to do something like this:
在您的情况下,您需要执行以下操作:
$yt = new Zend\namespace\Zend_Gdata_YouTube();