Custom Controller Directory Structure Symfony2

前端 未结 2 928
长情又很酷
长情又很酷 2021-01-23 10:10

I\'m transitioning a Kohana application to Symfony2. In Kohana I had to register a custom autoloader to make the framework see my controllers given my preferred directory struct

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 11:08

    Its not possible using the _controller key of a YAML resource file. This is the Symfony2 code that is executed:

    //classes.php, parse method

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

    As you can see "Controller" is concatenated after the Bundle namespace. Autoloading will use the namespace as a file path and the controller will never be found.

    If your using _Controller your controllers must be under the "Controller" folder that is immediately inside your Bundle directory.

提交回复
热议问题