Skip to content

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

Description

@trenyture

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'], '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/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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions