简体   繁体   中英

How do you send POST parameters to a function in PHP using Fat-Free-Framework?

The documentation on the website is a bit lacking ( http://fatfreeframework.com/routing-engine ). I want to use the shorthand expression of POST:

$f3->route('POST /login','Auth::login');

How do you send params into the Auth->login() function above?

This is an alternative way of writing it, but a bit longer:

$f3->route('POST /login',
    function($f3) {
        $params = $f3->get('POST');
        $Auth = new Auth;
        $Auth->login($params['username'], $params['password']);
    }
);

If you mean that the Auth::login should automatically receive the POST data as an argument, then you can't.

All F3 route handlers receive the following arguments:

  1. the framework instance
  2. the route tokens (if any)

See here for an example.

Anyway, if the Auth->login function you're referring to is the one included in the framework , then it couldn't work in any manner since the login() function is not a route handler . It simply returns TRUE or FALSE . A route handler has to do a little bit more than that: for example, to reroute the user on success or to display the login form again on error.

Try:

$f3->route('POST /login',
function($f3,$params) {
    $Auth = new Auth;
    $Auth->login($params['username'], $params['password']);
}
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM