Enable plugins to override panel routes

I see. I did a quick test. You can hijackin inernal routes by replacing the placeholder with an appropriate regex.

// toolkit/router.php

// The wildcard patterns supported by the router.
protected $patterns = array(
  '(:num)'     => '(-?[0-9]+)',
  '(:alpha)'   => '([a-zA-Z]+)',
  '(:any)'     => '([a-zA-Z0-9\.\-_%=]+)',
  '(:all)'     => '(.*)',
);

// The optional wildcard patterns supported by the router.
protected $optional = array(
  '/(:num?)'   => '(?:/([0-9]+)',
  '/(:alpha?)' => '(?:/([a-zA-Z]+)',
  '/(:any?)'   => '(?:/([a-zA-Z0-9\.\-_%=]+)',
  '/(:all?)'   => '(?:/(.*)',
);

So this one actually works.

panel()->routes(array(
  array(
    // 'pattern' => 'pages/(:all)/edit',
    'pattern' => 'pages/(.*)/edit',
    'method'  => 'GET',
    'action'  => function() {
      // do stuff
    },
  ),
));

Edit:
I just got it working for the search as well:

panel()->routes(array(
  array(
    // 'pattern' => 'search',
    'pattern' => '(search)',
    'method'  => 'GET|POST',
    'filter'  => array('auth'),
    'action'  => function() {
      // mimic search controller
    },
  ),
));
5 Likes