Symfony2 User Controller Directory Structure

I am transferring a Kohana application to Symfony2. In Cohan, I had to register a custom autoloader to make the infrastructure visible to my controllers, given my preferred directory structure. Is there an elegant way in Symfony2 to achieve routing for controllers where the Controller directory is below the level. For instance. Src / Somename / aBundle / Theme / Frontend / Controller / defaultController.php

0
source share
2 answers

You can place your controllers wherever you want, just import them into your routing.yml :

 controller: resource: @MyBundle/Theme/Frontend/Controller/ type: annotation 

Of course, this is just an example. You can find more information and many routing examples here: http://symfony.com/doc/current/book/routing.html

+1
source

Cannot use the _controller key of the YAML resource file. This is the symfony2 code that runs:

//classes.php, analysis method

  $try = $b->getNamespace() . '\\Controller\\' . $controller . 'Controller'; if (class_exists($try)) { return $try . '::' . $action . 'Action'; } 

As you can see, the “Controller” is merged after the Bundle namespace. Startup will use the namespace as the path to the file, and the controller will never be found.

If you use _Controller, your controllers must be located in the Controller folder, which is located directly in the Bundle directory.

0
source

Source: https://habr.com/ru/post/1260648/


All Articles