所以我用PHP做了一个路由系统......
所以我创建了一个名为 /post/:id 的路由,但是每当我 print_r my $matches 时,我都会得到:
数组 ( [0] => /post/10 [d] => 10 [1] => 10 ) 1
数组中的'd'显然应该是'id',有人知道如何解决这个问题吗?
谢谢
<?php
public function setPattern($pattern)
{
$this->_pattern = $pattern;
$this->_regex = preg_replace('#:([a-z])+$#', "(?P<$1>[^/]+)", $pattern);
}
public function match($uri)
{
if (!preg_match("#" . $this->_regex . "$#", $uri, $matches))
{
return false;
}
else
{
return $matches;
}
}