CodeIgniter路由不接受与路由表不同的异常
不知何故,我陷入了路由规则。我无法为超过路由规则的页面设置路由。例如,我在 doutes.php 中都有:
$route['(:any)/(:any)/(:any)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
因此,页面与地址正确加载:
- mypage.com/value1/value2/value2/value3/
- mypage.com/value.com/value1/value2/
,如果用户有意进入另一个用户值,它会抛出一个base_url()异常,该异常甚至都没有由我的404例异常来处理,所以我得到:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function base_url()
当然,我可以创建另一个规则来捕获4个值,但是5th值将丢弃该错误;)
我要实现的是找到一条规则,它将与任何超过最后一个规则的树相匹配,例如:
$route['(:any)/(:any)/(:any)/(no matter the value and tree)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)/(:any)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
即使用户类型:
- mypage.com/value.com/value1/value2/value3/4 也不会有任何错误/5/6/7/8/9 // 10/11/11 12/13/14/15/blabla/等...
我确定有解决方法:任何人都无法正常工作,它只会抓到一棵树),但是我没有找到任何树,我知道解决方案可能很简单,但是我还没有掌握CI路由...
预先感谢您任何提示。
somehow I got stuck with my routing rules. I can't set a routing for a page that exceeds the routing rule. For example I have in my routes.php:
$route['(:any)/(:any)/(:any)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
so the page loads properly with addresses:
- mypage.com/value1/value2/value3/
- mypage.com/value1/value2/
However if a user intentionally enters another value, it will throw a base_url() exception, which is not even handled by my 404 exceptions catch, so I get:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function base_url()
I can, of course, create another rule to catch 4th value but then, 5th value will throw that error ;)
What I want to achieve is to find a rule, that will match to ANY tree that exceed last rule, something like:
$route['(:any)/(:any)/(:any)/(no matter the value and tree)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)/(:any)'] = 'pages/view/$1/$2/$3';
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
So I won't have any errors even if a user type:
- mypage.com/value1/value2/value3/4/5/6/7/8/9//10/11/12/13/14/15/blabla/etc...
I'm sure there is a workaround for this (some regex there? (:any) or :any will not work, it will catch only one tree more), however I didn't found any and I'm aware that solution may be simple, but I didn't mastered CI routing yet...
Thank you in advance for any hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用像这样的普通正则:
更重要的问题是为什么不加载404?如果您的自定义404页面使用
base_url()
函数,则自动加载URL助手将解决该错误。You can use a normal regex like so :
The more important question is why doesn't that load a 404? If your custom 404 page is using the
base_url()
function, autoloading the url helper will fix that error.