snab
snab

Reputation: 65

regex in zf2 routing

Hi I am trying to pass a regex expression in zf2 routing, My router looks like this :

    'exampleroute' => array(
            'type'    => 'segment',
            'options' => array(

                    'route'    => '/exampleroute/[:regexparameter]',
                    'constraints' => array(

                             'regexparameter' => '[a-zA-Z][a-zA-Z0-9_-][$.]*',

                    ),
                    'defaults' => array(

                            '__NAMESPACE__' => 'Mynamespace\Controller',
                            'controller'    => 'exampleroute',
                            'action'        => 'example',
                    ),
            ),
    ),

I want to pass the following URL: http://mydomain.com/exampleroute/$2y$14$aPW5u7oGpuuMPRKRz6la1.m2SpJ2STFJ9BZ7giSwfKQxWKIuTODmW

but it gives me an error of "The requested URL could not be matched by routing."

Upvotes: 0

Views: 1902

Answers (2)

snab
snab

Reputation: 65

Its Working like this now:

'exampleroute' => array(
        'type'    => 'segment',
        'options' => array(

                'route'    => '/exampleroute/[:regexparameter]',
                'constraints' => array(

                         'regexparameter' => '[$.a-zA-z0-9_-]*',

                ),
                'defaults' => array(

                        '__NAMESPACE__' => 'Mynamespace\Controller',
                        'controller'    => 'exampleroute',
                        'action'        => 'example',
                ),
        ),
),

Upvotes: 0

mishik
mishik

Reputation: 10003

[a-zA-Z][a-zA-Z0-9_-][$.]* means:

  1. First symbol must be a-zA-Z
  2. Second symbol must be a-zA-Z0-9_-
  3. Followed by any number of $ or . symbols

I guess you need this:

[a-zA-Z0-9_-$.]*

Upvotes: 2

Related Questions