tags:

views:

35

answers:

2

How do I enforce a requirement that a paramater in a route be a string?

Given the route

my_foobar_route: url: /example/routing/:s1/:id requirements: { id: \d+ }

Can anyone remind me of how to force param s1 to be a string?

A: 

Pretty much anything that comes via the url is a string - any requirement is stronger than this, you you do not need to do anything, your parameter is already a string. Maybe you want a specially formatted string?

Maerlyn
+1  A: 

You just need to supply a suitable regular expression:

my_foobar_route:
  url: /example/routing/:s1/:id
  requirements:
    id: \d+
    s1: [a-zA-Z]+
richsage