[英]How to use third party package in Laravel?
I'm using Laravel 4 and I want to use a third party package within this framework. 我正在使用Laravel 4,并且想在此框架内使用第三方软件包。 I did this to install it:
我这样做是为了安装它:
1) Add package name to composer.json file 1)将软件包名称添加到composer.json文件
2) Run composer update
command 2)运行
composer update
命令
Now I have package available in /vendors folder. 现在,我在/ vendors文件夹中有可用的软件包。 My question is, how to use it inside the Laravel now?
我的问题是,现在如何在Laravel中使用它?
Looking in the config/app.php file, I can not add it to "providers" array as far as I can see, nor "aliases". 在config / app.php文件中,我无法将其添加到“ providers”数组中,也无法将其添加到“ aliases”中。
When I try to instantiate that package class directly in controller I get the error "Class not found" ( I tried full name to the class: $pack = new /vendor/package.../class.php
) 当我尝试直接在控制器中实例化该包类时,出现错误“找不到类”(我尝试使用该类的全名:
$pack = new /vendor/package.../class.php
)
Any help on how to include and use the class in the laravel greatly appreciated 非常感谢有关如何在Laravel中包含和使用该类的任何帮助
If the package provides a ServiceProvider, add it to app/config/app.php
. 如果软件包提供了ServiceProvider,请将其添加到
app/config/app.php
。
Otherwise composer has already took care of autoloading for you, so you just have to: 否则,作曲家已经为您完成了自动加载的工作,因此您只需要:
$package = new Package;
In the cases where the package is namespaced, you'll have to: 在包被命名空间的情况下,您必须:
$package = new PackageNamespace\Package;
To be sure, take a look at the vendor/composer/autoload_*
files, usually vendor/composer/autoload_classmap.php
, search for the package name or class name and you'll see how it is named. 可以肯定的是,查看一下
vendor/composer/autoload_*
文件,通常是vendor/composer/autoload_classmap.php
,搜索包名称或类名称,您将看到其命名方式。 Or just take a look at the main package souce file, usually in: 或者只是看一下主要的包源文件,通常在:
vendor/vendorName/packageName/[src or lib or whatever]/Package.php
EDIT 编辑
I just installed it here and did: 我只是在这里安装它,并做了:
Route::get('test', function()
{
dd(new WideImage\WideImage);
});
Works like a charm. 奇迹般有效。 This package is in the 'namespaced' case I wrote above.
这个包是我上面写的“命名空间”案例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.