Skip to content

Latest commit

 

History

History
61 lines (52 loc) · 2.95 KB

2.Routes.md

File metadata and controls

61 lines (52 loc) · 2.95 KB

Routes

ZfcAdmin enables a single route named zfcadmin, which is a literal route and standard using the url /admin. You can create child routes under zfcadmin so you enable urls like /admin/foo or /admin/bar/baz.

Add child route

To register a route as child route, the following example takes the option you name that route foo. The complete path should look like /admin/foo, so foo is a literal route with the route value /foo. Say you want this route to connect to your MyModule\Controller\MyController controller and the index action, create this config in your module.config.php:

'router' => array(
    'routes' => array(
        'zfcadmin' => array(
            'child_routes' => array(
                'foo' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => '/foo',
                        'defaults' => array(
                            'controller' => 'MyModule\Controller\MyController',
                            'action'     => 'index',
                        ),
                    ),
                ),
            ),
        ),
    ),
),

Change the /admin url

If you want your admin interface at /backend or something else, you must override the value of the route. In the following config, the /admin route value is replaced with /backend. Make sure this is enabled in a config where the module is registered later than ZfcAdmin (otherwise, the config will not overwrite ZfcAdmin's configuration):

'router' => array(
    'routes' => array(
        'zfcadmin' => array(
            'options' => array(
                'route'    => '/backend',
        ),
    ),
),

Change the controller behind /admin

By default, the /admin url links to the ZfcAdmin\Controller\AdminController controller. It's an empty action and a simple view script is rendered. If you want, for example, create a dashboard on the admin index page, you probably need to point the route to another controller. In the following config, the zfcadmin route's controller is replaced with MyModule/Controller/AdminController and the action is set to dashboard. Make sure this is enabled in a config where the module is registered later than ZfcAdmin (otherwise, the config will not overwrite ZfcAdmin's configuration):

'router' => array(
    'routes' => array(
        'zfcadmin' => array(
            'options' => array(
                'defaults' => array(
                    'controller' => 'MyModule/Controller/AdminController',
                    'action'     => 'dashboard',
                ),
            ),
        ),
    ),
),

Link to documentation pages

  1. Introduction
  2. Routes
  3. Navigation
  4. Authorization
  5. Views & Layout