klein / klein.php

A fast & flexible router
MIT License
2.66k stars 290 forks source link

Question: how use parameter in route? #408

Closed KitaXvost closed 3 years ago

KitaXvost commented 3 years ago
require_once 'vendor/autoload.php';
require_once 'UserController.php';

$klein = new \Klein\Klein();

$klein->get('/user/[i:id]', [new UserController(), 'get_user']);
$klein->dispatch();

UserController.php

function get_user($id)
  {
    echo $id;    
  }

I get an error: Fatal error: Uncaught Error: Object of class Klein\Request could not be converted to string and Klein\Klein->dispatch( $request = ???, $response = ???, $send_response = ???, $capture = ??? tell me how to use the parameters correctly in my simple example