我正在尝试使用Kohana中的路由类将URL更改为另一个URL。
这是我的链接:
<a class="btn" target="_self" href="<?php echo URL::base(). $current_channel->name;?>/materials/28" title="Materials Download">
<div class="txt">MATERIALS</div>
</a>
这给了我链接:localhost:8081/channel/materials/28
,因为我正在使用php -S localhost:8081
在本地服务器上运行>
这是我的路线规格:
Route::set('c_materials', '<channel_name>/materials(/<id>)', array('channel_name' => $channel_names)) ->defaults(array( 'controller' => 'materials', 'action' => 'brands', )); Route::set('materials', 'materials(/<id>)') ->defaults(array( 'controller' => 'materials', 'action' => 'brands', ));
但是出于某种奇怪的原因,我无法弄清楚,Kohana在
routes.php
文件中找不到链接并抛出此错误:
ErrorException [ Warning ]: preg_match(): Compilation failed: unmatched parentheses at offset 50
查看错误日志,这是在preg_match
中传递给Routes.php
的参数:
这是我第一次使用Kohana,所以我不知道为什么它使用这种奇怪的模式来匹配我的URL。这也在其他页面中发生,对于不同的URL使用相同的模式,这一直在破坏我的系统。
我尝试更改路由名称,强制路由仅接受materials/28
处的URL,但由于此模式用于与我的URL比较而没有任何效果。我该如何更改?
编辑: