我正在尝试在CodeIgniter上创建一个路由,该路由匹配3个数字后跟连字符后跟任何内容。到目前为止,我没有运气。我尝试了以下内容:
$route['([0-9]+)-([a-zA-Z0-9]+)'] = 'product/index/$1';
$route['([0-9]+)([a-zA-Z0-9-]+)'] = 'product/index/$1';
$route['(:num)-(:any)'] = 'product/index/$1';
$route['([0-9]{3})-(:any)'] = 'product/index/$1';
$route['(\d{3})-(:any)'] = 'product/index/$1';
等等。有谁知道我怎么能这样做?
答案 0 :(得分:0)
看起来CodeIgniter不使用标准正则表达式。
试试这些:
(\d{3})\-.*
(\d{3})-.*
(\d{3})\-(:any)
(\d{3})-(:any)
其中一个应该可以工作。
有关详细信息,请参阅 http://codeigniter.com/user_guide/general/routing.html
答案 1 :(得分:0)
这可能是一个参数问题。 也许你应该尝试:
$route['([0-9]+)-([a-zA-Z0-9]+)'] = 'product/index/$1/$2';
由于您正在捕获2个变量,因此您似乎应将它们都传递给函数。