How I can make this route rule works?

$router->add('/Device/{mac:(?:[a-f0-9]{2}:){5}(?:[a-f0-9]{2})}', ['controller' => 'Device', 'action' => 'index']);

I try to print $this->dispatcher->getPrams(); I get Array(mac => 1).

Thanks.

What exactly doesn't work? You can access it by

    public function indexAction() {
        $params = $this->dispatcher->getPrams();
        $mac = $params['mac']
    }

But if you want to that params to be like 0 => .. , 1 => .. then your code shoould be

    $router->add(
        '/Device/(?:[a-f0-9]{2}:){5}(?:[a-f0-9]{2})', 
        [
            'controller' => 'Device',
            'action' => 'index',
            'params' => 1
        ]
    );

Correct me if I'm wrong!!



17.0k
public function indexAction() {
        $params = $this->dispatcher->getPrams();
        print_r($params);
    }

the output is:

Array ( [mac] => 1 ), so what is wrong?

Have you tried running your pattern against a URL you think it should match against? Not as a route - just write some test code to see if your pattern works.