.. _controllers: Controllers ############# This pages gives an quick overview of the controllers used in an Mapbender3 application. The Front Controller - Using Routes *********************************** In Symfony2, each HTTP request goes trough the (one-and-only) front end controller (app.php in the web directory) which determines the controller funtion to pass it to. The mapping from request path to controller function is basically done in the configuration, where the routing.yml defines these mappings - called routes - or imports their definitions from bundles (or other files). To get an overview off all defined routes by using the console command .. code-block:: yaml cd mapbender3/application app/console router:debug [router] Current routes Name Method Pattern _assetic_30d3bc4 ANY /css/30d3bc4.css _assetic_30d3bc4_0 ANY /css/30d3bc4_part_1_base_1.css _wdt ANY /_wdt/{token} _profiler_search ANY /_profiler/search _profiler_purge ANY /_profiler/purge _profiler_import ANY /_profiler/import _profiler_export ANY /_profiler/export/{token}.txt _profiler_search_results ANY /_profiler/{token}/search/results _profiler ANY /_profiler/{token} _configurator_home ANY /_configurator/ _configurator_step ANY /_configurator/step/{index} _configurator_final ANY /_configurator/final mapbender_manager_layer_index GET /manager/layers/{page} mapbender_manager_group_index GET /manager/group/{page} mapbender_manager_repository_index GET /manager/repository/{page} mapbender_manager_application_index2 GET /manager/application mapbender_manager_application_index GET /manager/applications/{page} mapbender_manager_application_new GET /manager/application/new mapbender_manager_application_create POST /manager/application mapbender_manager_application_view ANY /manager/application/{id} [ and so on... ] The command lists all routes with their names, allowed methods and URL pattern. To get more information about a particular route, give it's name to the command: .. code-block:: yaml app/console router:debug mapbender_core_user_login [router] Route "mapbender_core_user_login" Name mapbender_core_user_login Pattern /user/login Class Symfony\Component\Routing\CompiledRoute Defaults _controller: Mapbender\CoreBundle\Controller\UserController::loginAction Requirements Options compiler_class: Symfony\Component\Routing\RouteCompiler Regex #^ /user/login $#x To learn more about routing, read the `Symfony Book `_. Defining routes using annotations ********************************* In Mapbender3 we use a decentralized route definitions: Instead of writing each and every route in the routing.yml, we import their definition from the controller classes in the activated bundles. This has the advantage of having the definition with the controller function. This should usually be fine and can be - if need arises - easily overwritten by adapting the routing.yml. Using the Symfony2 with the SE bundles like Mapbender3 does, routes can therefore be written using annotation comments for each controller function. You can read about the annotation syntax over at the `Symfony2 documentation `_. Mapbender3 Controllers ********************** A Mapbender3 installation with use a particular set of controller classes and functions. This chapter will give an short list of these, so you can inspect them more easily. Frontend ~~~~~~~~ The frontend is basically "the application" (or GUI as it has been called in Mapbender 2 - and even there this term was incorrect). Each application is routed to the ApplicationController class of the CoreBundle: .. code-block:: yaml /application/{slug} => Mapbender\CoreBundle\Controller\ApplicationController->applicationAction($slug) Elements of an application can provide Ajax endpoints for their client side widgets. These are routed as follows: .. code-block:: yaml /application/{slug}/element/{id}/{action} => Mapbender\CoreBundle\Controller\ApplicationController->elementAction($slug, $id, $action) **Note:** This controller calls the **httpAction** method if the element class and passes the $action parameter and returns the response given by that function. So for the real magic for element Ajax behaviour take a look at the httpAction method of the elements. Backend ~~~~~~~ The backend is handled by the ManagerBundle, which provides (will provide) an consistent backend for managing all aspects of an Mapbender3 application: applications, layers, elements, users, settings. For each section a own controller class exists within this bundle: * ApplicationController - Manage applications * GroupController - Manage user groups * LayerController - Manage layers * RepositoryController - Manage the layer repository * SettingsController - Manage common settings * UserController - Manage users * plus an ManagerController which provides some common functionality for the other controllers. Each of the these controllers (right now work is going on within the ApplicationController) is a good example of what we think of as good kinda RESTful URLs.