简体   繁体   English

如何将symfony捆绑软件应用于Laravel?

[英]How to apply symfony bundle to Laravel?

\\I heard that Laravel was made with symfony, php framework. \\我听说Laravel是用symfony php框架制作的。 So, I thought symfony bundle will work at Laravel, too. 因此,我认为symfony bundle也可以在Laravel中使用。

IgorwFileServeBundle github IgorwFileServeBundle的github

I want to install it to Laravel "5.1.*". 我想将其安装到Laravel“ 5.1。*”。 So I edited this line at composer.json. 因此,我在composer.json中编辑了这一行。

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "igorw/file-serve-bundle": "~1.0"
},

then I executed composer update . 然后我执行了composer update readme.md say I have to add it to my app's kernel. readme.md说我必须将其添加到我的应用程序的内核中。

public function registerBundles()
{
    $bundles = array(
        // ...
        new Igorw\FileServeBundle\IgorwFileServeBundle(),
        // ...
    );
    // ...
}

So I added it to my kernel. 因此,我将其添加到了内核中。

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \Igorw\FileServeBundle\IgorwFileServeBundle::class,
];

But When I save and go to my app at brower, FatalErrorException in Bundle.php line 29: Class 'Symfony\\Component\\DependencyInjection\\ContainerAware' not found was appear. 但是,当我在浏览器中保存并转到我的应用程序时, Bundle.php第29行中出现FatalErrorException:找不到类'Symfony \\ Component \\ DependencyInjection \\ ContainerAware'

What I'm wrong? 我错了吗?

Symfony and Laravel are 2 completely different frameworks. Symfony和Laravel是2个完全不同的框架。 Symfony is build on top of 20+ (maybe even 30+) Symfony components (standalone libraries created by the Symfony team). Symfony建立在20多个(甚至30多个)Symfony组件(由Symfony团队创建的独立库)之上。 These components are bound together by the framework bundle and the framework that was created is called the Symfony full-stack framework. 这些组件由框架捆绑包绑定在一起,并且创建的框架称为Symfony全栈框架。

Some of these components are also used by Laravel. Laravel也使用其中一些组件。 The Laravel framework is just another way of glueing these components together. Laravel框架只是将这些组件粘合在一起的另一种方法。 Silex, another framework, is yet another way of binding these components. Silex是另一个框架,是绑定这些组件的另一种方法。

Bundles is a concept from the Symfony full-stack component (HttpKernel component actually). Bundles是来自Symfony 全栈组件(实际上是HttpKernel组件)的概念。 Laravel does not use this, so you can't use any bundles in Laravel. Laravel不使用它,因此您不能在Laravel中使用任何捆绑软件。

If you need to use a Symfony bundle, you need to have a Symfony application. 如果需要使用Symfony捆绑包,则需要一个Symfony应用程序。 Fortunately for your, Laravel has a big community as well. 对您来说幸运的是,Laravel也拥有一个庞大的社区。 It's very likely that there is a Laravel package implementing the same feature for the Laravel framework. 很可能有一个Laravel软件包为Laravel框架实现了相同的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM