Kohana 3 路线 - 空正则表达式
直到最近我才有了一个路由处理程序控制器,所有请求都通过它传递。这样我就可以根据目录中的条目将某些项目定向到某些页面。然而,由于某种原因,它最近停止工作并给出了以下错误:
ErrorException [ Warning ]: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Empty regular expression
这来自于route.php 文件中的matches() 函数。
在调用该类之前,我注意到 $uri 变量确实包含一个字符串,但是一旦进入该函数,它就会变成 NULL,从而解决错误。
// Routes for product items
foreach($items as $item)
{
Route::set($item->seoUrl, $item->seoUrl)
->defaults(array(
'controller' => 'item',
'action' => 'index',
'id' => $item->id,
));
}
// Error
Route::set('error', 'error(/<action>(/<id>))', array('id' => '.+'))
->defaults(array(
'controller' => 'error',
'action' => '404',
'id' => FALSE,
));
// Standard - normal Kohana behaviour
Route::set('standard', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'catalogue',
'action' => 'index',
));
// RouteHandler Reset - otherwise continuous loop
Route::set('routeHandler', '£€%')
->defaults(array(
'controller' => 'routeHandler',
'action' => 'index',
));
$uri = $this->request->param('uri');
$request = new Request($uri);
echo $request->execute()
->send_headers()
->response;
产品项目的路线仍然有效。这让我相信这是引起不安的标准路线。重置路由必须在那里,否则我会通过routeHandler 得到一个持续的循环。
奇怪的是,这完成了所有工作,据我所知,这个脚本没有任何改变。
任何想法都将不胜感激。
Up until recently I have had a routehandler controller through which all requests pass. This is so that I can direct certain items to certain pages based on entries in a catalogue. However for some reason it has recently stopped working and gives me the following error:
ErrorException [ Warning ]: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Empty regular expression
This comes from the matches() function in the route.php file.
Up until that class is called I have noticed that the $uri variable does contain a string, however once in that function it turns to NULL which throughs the error.
// Routes for product items
foreach($items as $item)
{
Route::set($item->seoUrl, $item->seoUrl)
->defaults(array(
'controller' => 'item',
'action' => 'index',
'id' => $item->id,
));
}
// Error
Route::set('error', 'error(/<action>(/<id>))', array('id' => '.+'))
->defaults(array(
'controller' => 'error',
'action' => '404',
'id' => FALSE,
));
// Standard - normal Kohana behaviour
Route::set('standard', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'catalogue',
'action' => 'index',
));
// RouteHandler Reset - otherwise continuous loop
Route::set('routeHandler', '£€%')
->defaults(array(
'controller' => 'routeHandler',
'action' => 'index',
));
$uri = $this->request->param('uri');
$request = new Request($uri);
echo $request->execute()
->send_headers()
->response;
The routes for product items still works. Which leads me to believe its the standard route which is causing upset. The reset route has to be there otherwise I get a constant loop through the routeHandler.
Strange thing is this did all work, and nothing has changed in this script to my knowledge.
Any ideas though would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。
其中一个项目的 seoUrl 基本上为“” NULL,因此通过将其作为路由,会混淆此控制器中设置的所有以下路由。
现在添加了一个检查以确保 $item->seoURL 不为空。
Solved it.
One of the items had an seoUrl of "" NULL basically, so by having this as a route it was confusing all the following routes set in this controller.
Have added a check now to make sure that the $item->seoURL is not empty.