Get information about the route executed in Fat Free v3

穿精又带淫゛_ 提交于 2020-01-14 14:11:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!