Used with Symfony
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DependencyInjection
Resources/config
AizattoControllerResolverBundle.php
ControllerResolver.php
README.md

README.md

README

When it comes to Symfony development, I prefer one controller per endpoint. This is because my experience with Symfony has resulted in many fat controllers, and it has become easier to manage the controllers when it is one endpoint per controller.

When you begin developing a Symfony application, you will put actions related to a particular model into one controller. This would result in an extermely large (in terms of lines of code) controller.

Then you'll move those actions into a different controller.

So I wanted an easy way to standardize the function that gets called for each controller.

Example Controller:

class DefaultController extends Controller {
  
  public function getResponse() {
    return new Response($content);
  }

}

Example Route:

aizatto_controller_resolver_bundle_default:
    pattern: /
    defaults: { _controller: "AizattoControllerResolverBundle:Default" }

Installation

Install source code

You have two options to install the source code.

  • deps file
  • git submodules

Install via deps

Add into your deps file

[AizattoControllerResolverBundle]
     git=http://github.com/aizatto/AizattoControllerResolverBundle.git
     target=/bundles/Aizatto/Bundle/ControllerResolverBundle

Execute vendor update script:

php bin/vendors update

Install via git submodules

Execute git submodule add command:

git submodule add \
  http://github.com/aizatto/AizattoControllerResolverBundle.git \
  vendor/bundles/Aizatto/Bundle/ControllerResolverBundle

Install into AppKernel

Add "Aizatto\Bundle\ControllerResolverBundle\ControllerResolverBundle()" to the list of bundles.

public function registerBundles()
{
    $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        ...
        new Aizatto\Bundle\ControllerResolverBundle\ControllerResolverBundle();
    );

Install into autoload

Edit app/autoload.php, and add the register the namespace "Aizatto":

$loader->registerNamespaces(array(
  'Aizatto' => __DIR__.'/../vendor/bundles',
))

Install route

We have to write the routes individually for each controller.

For example if we have the controller "DefaultController" in your bundle "AizattoControllerResolverBundle".

We add to app/config/routing.yml:

aizatto_controller_resolver_bundle_default:
    pattern: /
    defaults: { _controller: "AizattoControllerResolverBundle:Default" }

Then visit in your brower http://localhost/dev.php/