On Wed, Aug 14, 2013 at 10:14 AM, ravidhu <ravidhu.di...@gmail.com> wrote:
> I have a couple of routes that don't work and i don't understand why because
> all the others works, here my module.config.php :

Based on what you provided, I think the most likely problems are:

- Order of matching (routes are matched in reverse order in which they
are defined)
- optional/required parameter problems

Try the following definitions. They do the following:

- Literal routes are pushed later, ensuring they match before segment
routes that define the top-level sement.
- I combined the "search" and "detail" routes, making "detail" a child
route of "search" (i.e., you will need to refer to it as
"search/detail"). This will ensure that the router does not try to
match an identifier unless a location is also present. This should
speed matching, as well as slim down the definition slightly.

Try it, and let me know if it works!

'routes' => array(
    'search' => array(
        'type'    => 'Segment',
        'options' => array(
            'route'    => '/:type[/:location]',
            'constraints' => array(
                'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
            ),
            'defaults' => array(
                'controller' => 'FrontApp\Controller\Index',
                'action'     => 'search',
            ),
        ),
        'may_terminate' => true,
        'child_routes' => array(
            'detail' => array(
                'type'    => 'Segment',
                'options' => array(
                    'route'    => '/:id',
                    'constraints' => array(
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'action' => 'detail',
                    ),
                ),
            ),
        ),
    ),
    'confirm' => array(
        'type'    => 'Literal',
        'options' => array(
            'route'    => '/confirm',
            'defaults' => array(
                'controller' => 'FrontApp\Controller\Index',
                'action'     => 'confirm',
            ),
        ),
    ),
    'user' => array(
        'type'    => 'Literal',
        'options' => array(
            'route'    => '/connexion',
            'defaults' => array(
                'controller' => 'FrontApp\Controller\User',
                'action'     => 'index',
            ),
        ),
    ),
    'front' => array(
        'type'    => 'Literal',
        'options' => array(
            'route'    => '/',
            'defaults' => array(
                'controller' => 'FrontApp\Controller\Index',
                'action'     => 'index',
            ),
        ),
    ),
),


>
> <pre>
>
> return array(
> 'controllers' => array(
>     'invokables' => array(
>         'FrontApp\Controller\Index' =>
> 'FrontApp\Controller\IndexController',
>         'FrontApp\Controller\User' => 'FrontApp\Controller\UserController',
>     ),
> ),
>
>
> 'router' => array(
>     'routes' => array(
>         'confirm' => array(
>             'type'    => 'Literal',
>             'options' => array(
>                 'route'    => '/confirm',
>                 'defaults' => array(
>                     'controller' => 'FrontApp\Controller\Index',
>                     'action'     => 'confirm',
>                 ),
>             ),
>         ),
>         'user' => array(
>             'type'    => 'Literal',
>             'options' => array(
>                 'route'    => '/connexion',
>                 'defaults' => array(
>                     'controller' => 'FrontApp\Controller\User',
>                     'action'     => 'index',
>                 ),
>             ),
>         ),
>         'detail' => array(
>             'type'    => 'Segment',
>             'options' => array(
>                 'route'    => '/:type/:location/:id',
>                 'constraints' => array(
>                     'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
>                     'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
>                     'id'       => '[0-9]+',
>                 ),
>                 'defaults' => array(
>                     'controller' => 'FrontApp\Controller\Index',
>                     'action'     => 'detail',
>                 ),
>             ),
>         ),
>         'search' => array(
>             'type'    => 'Segment',
>             'options' => array(
>                 'route'    => '/:type[/:location]',
>                 'constraints' => array(
>                     'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
>                     'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
>                 ),
>                 'defaults' => array(
>                     'controller' => 'FrontApp\Controller\Index',
>                     'action'     => 'search',
>                 ),
>             ),
>         ),
>         'front' => array(
>             'type'    => 'Literal',
>             'options' => array(
>                 'route'    => '/',
>                 'defaults' => array(
>                     'controller' => 'FrontApp\Controller\Index',
>                     'action'     => 'index',
>                 ),
>             ),
>         ),
>     ),
> ),
>
> 'view_manager' => array(
>     'display_not_found_reason' => true,
>     'display_exceptions'       => true,
>     'doctype'                  => 'HTML5',
>     'not_found_template'       => 'error/404',
>     'exception_template'       => 'error/index',
>     'template_map' => array(
>         'layout/layout'           => __DIR__ .
> '/../view/layout/front-layout.phtml',
>         'layout/frontlayout'           => __DIR__ .
> '/../view/layout/front-layout.phtml',
>         'frontapp/index/index' => __DIR__ .
> '/../view/front-app/index/index.phtml',
>         'error/404'               => __DIR__ . '/../view/error/404.phtml',
>         'error/index'             => __DIR__ . '/../view/error/index.phtml',
>     ),
>     'template_path_stack' => array(
>         'front' => __DIR__ . '/../view',
>         'searcher' => __DIR__ . '/../view',
>         'detail' => __DIR__ . '/../view',
>         'user' => __DIR__ . '/../view',
>         'confirm' => __DIR__ . '/../view',
>     ),
> ),
> 'module_layouts' => array(
>         'FrontApp' => 'layout/frontlayout',
>         'BackApp' => 'layout/backlayout',
> ),);
>
> </pre>
>
> so when i try :
>
> mywebsite/ -> work
>
> mywebsite/one-type -> work
>
> mywebsite/one-type/one-location -> don't work
>
> mywebsite/one-type/one-location/on-id -> don't work
>
> mywebsite/connexion ->work
>
> mywebsite/confirm ->work
>
> I'm little bit confused because its like you can't use different route type.
> So, for the route that don't work i either have "....Unable to render
> template layout/layout..." error which is resolve when i add 'layout/layout'
> with the same path that 'layout/frontlayout' in template_map key (i also
> don't really understand why but it work, so if you can enlighten me, i will
> be very thankful), or, a "The requested URL could not be matched by
> routing." and for this error, i'm stuck because i don't see where is the
> issue :/
>
> hope you can help :)
>
>
>
> --
> View this message in context: 
> http://zend-framework-community.634137.n4.nabble.com/ZF2-matched-by-routing-tp4660753.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>



-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to