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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With