Yury
Yury

Reputation: 928

How to do without the bundle name in Symfony 2?

Is there a way to do without the package name in the parts of the system as View or Routing?

For example, I want to use instead:

{% extends "SomeAppBundle::layout.html.twig" %}

Use this:

{% extends "layout.html.twig" %}

Or:

    $router->add('index', new Route('/', array(
         '_controller' => 'SomeAppBundle:Default:index',
    )));

Replace:

    $router->add('index', new Route('/', array(
         '_controller' => 'Default:index',
    )));

I did not fully understood the compulsion to bundles, but I think that this approach is more obvious for applications with single bundle. Why specify bundle name if I'm in the space of this bundle?

Upvotes: 1

Views: 63

Answers (1)

Sgoettschkes
Sgoettschkes

Reputation: 13189

The symfony docs say:

Before you begin, you'll need to create a bundle. In Symfony2, a bundle is like a plugin, except that all of the code in your application will live inside a bundle.

If you have the rare case of having really only one bundle, than you may see this as overhead. But even then there are advantages:

  • Your application looks the same no matter if it has one or 10 bundles
  • If you need another bundle, you don't have to change everything ("Oh, we might need a Backend").
  • The core does not need to handle different cases

I would advice you to work with the framework, creating one bundle even if it's the only one. You won't really feel it once you created it and it makes things so much easier.

Upvotes: 1

Related Questions