PHP-Router icon indicating copy to clipboard operation
PHP-Router copied to clipboard

Controller method with custom params (ids parameters excluded) throw Too few arguments Exception

Open brodalee opened this issue 5 years ago • 0 comments

  • PHPRouter version: @dev-master
  • PHP version:
  • Exact steps to cause this issue
    1. Create abstraction of router.
    2. Create controllers with customs params and at first the id, and load routes.
    3. Sending request.
  • What you expected
    • e.g. I expected to get my custom params with the id.
  • What happened instead
    • e.g. Instead, I got Error : Too few arguments to function Controller::test(), 1 passed and exactly 2.

Hey ! just found an exception about controllers method params. I wanted to pass (with or without url dynamic param) some custom object like a RequestObject.

To fix it, in Router.php, match() function, just before call $routes->setParameters($params);, add

foreach ($routes->getParameters() as $parameter) {
           $params[] = $parameter;
}

Thanks you.

brodalee avatar Aug 21 '20 22:08 brodalee