【问题标题】:Is it possible for FuelPHP not to allow the right side of the route?FuelPHP有可能不允许路线的右侧吗?
【发布时间】:2012-04-01 06:52:44
【问题描述】:
在config/routes.php
<?php
return array(
'account/profile/change_password' => 'users/account/change_password',
);
我可以在浏览器中访问site.com/users/account/change_password和site.com/users/account/change_password。
有没有办法将其限制在仅左侧(即site.com/users/account/change_password)?
【问题讨论】:
标签:
php
fuelphp
fuelphp-routing
【解决方案1】:
仅通过特定路由,例如将其路由到与您的_404_ 控制器相同的位置。当然你也可以为整个控制器做这件事:
'users/account(/:any)' => 'my/404/route',
这样,对这个控制器的直接调用总是会转到您的 404。
当然,如果您的路由以 ':any' => 'catch/everything/$1' 之类的通配符路由结束,则您不需要这样做。
【解决方案2】:
完整:如果您只想允许 HMVC 调用,但不允许 URI 访问,您也可以在控制器本身中捕获它。在 before() 方法中(对于整个控制器)或在单个方法中:
// throw a 404 if accessed via the URI
if ( ! \Request::active()->is_hmvc())
{
throw new \HttpNotFoundException();
}