How do I use FastRoute?

后端 未结 3 634
悲&欢浪女
悲&欢浪女 2021-02-02 15:22

I\'m attempting to use the FastRoute routing library and can\'t get the simple usage example to work.

Here is the basic usage example found on the GitHub page:



        
3条回答
  •  感动是毒
    2021-02-02 16:10

    Example how to handle request

    $r->addRoute('GET', '/users', 'User/getUsers');
    

    Then if dispatcher found, you can process it like following

    case FastRoute\Dispatcher::FOUND:
        $handler = $routeInfo[1];
        $vars = $routeInfo[2];        
        list($class, $method) = explode("/", $handler, 2);
        call_user_func_array(array(new $class, $method), $vars);
    
        break;
    

    Don't forget to create class User with getUsers() method.

提交回复
热议问题