问题
I'd like to know which route is executed according to current URL in the beforeRoute
method in the Fat Free Framework.
In other words, can I get which class and which method will be executed? I had info about about the pattern (URL) in PATTERN variable but I don't know which class and method is going to be executed for this PATTERN as mapped in routes.ini.
Example of my routes.ini:
GET /admin=Controllers\Admin\Admin->index
In this case I'd like to find that the class is Controllers\Admin\Admin
and the method is index.
I've found how to get the class:
get_class($this)
But I haven't found how to get the method name. Please remember that I have to get the method name from the beforeRoute
method.
回答1:
i've foud it here is the solution, it may help some one.
To get the method name that will be executed in the route :
$hive = $f3->hive();
$tmp = explode('->',$hive['ROUTES'][$f3->get('PATTERN')][3][$hive['VERB']][0]);
So $tmp[0] will contain the class name and $tmp[1] will containt de method name.
回答2:
short and sweet version
$request = $this->f3->get('PARAMS.0');
then you can check if the $request has what you are looking for
Example
if(!$this->f3->exists('SESSION.userId')){
if (!$this->strpos($request,'login')) {
$this->f3->reroute('/login');
exit;
}
}
More details on PARAM
The first array index of PARAM contains the URI, from there PARAM will contain any route query variables.
Sample URL: http://localhost/user/edit/@id/@whatever
PARAMS[0]=/user/edit/foo/bar
PARAMS[id]=foo
PARAMS[whatever]=bar
来源:https://stackoverflow.com/questions/16575687/get-information-about-the-route-executed-in-fat-free-v3