Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the method used in the controller? #378

Open
trenyture opened this issue Dec 28, 2017 · 1 comment
Open

How to get the method used in the controller? #378

trenyture opened this issue Dec 28, 2017 · 1 comment

Comments

@trenyture
Copy link

trenyture commented Dec 28, 2017

Hi, I have a question about your great router ...
I'm implementing it in my project and I had a question ... From my controller how can i Know which method was used? Post, Get, Patch or Delete?
Example :
In my routes.php file I have :
$klein->respond(['GET', 'PATCH'], '/posts/create', ['PostsController', 'create']);
So how in my controller I can know if the function was called in GET or in PATCH?
public static function create($req, $res, $serv, $app)
{
if (PATCH) {
//save to bdd
} else {
$params = [
'datas'=> [
'pageTitle' => 'Créer un nouveau Post'
],
];
echo $app->twig->render('Posts/create.html', $params);
}
}
Thanks you

edit :
Sorry, I know that in pure php you can use $_SERVER['REQUEST_METHOD'] to know the method used, but maybe in your Klein router you provide it?

@MartinSerdar
Copy link

According to the API docs, you can retrieve the Request Method via $request->method()!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants