mrkrstphr
4/23/2014 - 7:42 PM

ZF3 Router Example

ZF3 Router Example

<?php

// current: 

'dash_router' => [
    'routes' => [
        'user' => ['/user', 'user', 'index', 'children' => 
        [
            'create' => ['/create', 'Application\Controller\UserController', 'create', ['get', 'post']],
            'edit' => ['/edit/:id', 'edit', 'Application\Controller\UserController', ['get', 'post'], 'constraints' => ['id' => '\d+']],
            'delete' => ['/delete/:id', 'edit', 'Application\Controller\UserController', 'constraints' => ['id' => '\d+']],
        ]],
    ],
],

// suggested:

'dash_router' => [
    'routes' => [
        'user' => ['/user', 'user', 'index', ['children' => 
        [
            'create' => ['/create', 'Application\Controller\UserController', 'create', ['get', 'post']],
            'edit' => ['/edit/:id', 'edit', 'Application\Controller\UserController', ['get', 'post'], ['constraints' => ['id' => '\d+']]],
            'delete' => ['/delete/:id', 'edit', 'Application\Controller\UserController', ['constraints' => ['id' => '\d+']]],
        ]]],
    ],
],

// difference being:

'constraints' => ['id' => '\d+']

// vs

['constraints' => ['id' => '\d+']]

// Now the whole route config array is index-based