Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

The routing system that drupal 8 offers is flexible in terms of validation. It is possible to validate your route against some typical regex lines. 

Example 1

{id} placeholder should be a numeric character. 

/path/test/1 will be valid
/path/test/test will be 'page not found'

mymodule.controller:
  path: '/path/{method}/{id}'
  defaults:
    _controller: '\Drupal\mymodule\Controller\mymoduleSaveController::Render'
    _title_callback: '\Drupal\mymodule\Controller\mymoduleSaveController::getTitle'
  requirements:
    _access: 'TRUE'
    id: '\d+'

Example 2 

{name} placeholder should string and contains only uppercase and lowercase alphabet.

/example/test will be valid
/example/100 will be 'page not found'

example.user
  path: '/example/{name}'
  defaults:
    _controller: '\Drupal\example\Controller\ExampleController::content'
  requirements:
    _permission: 'access content'
    name: '[a-zA-Z]+'

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon