0

Based on the documentation of Aura Router, in order to define a new path (e.g. for GET method), we can use this code snippet:

 $map->get('blog.read', '/blog/{classname}/{method}/{param}', function ($request) {
    $className = $request->getAttribute('classname');
    $methodName = $request->getAttribute('method');
    $param = $request->getAttribute('param');

    $response = new Zend\Diactoros\Response();
    $response->getBody()->write("You asked for blog entry {$id}.");
    return $response;
});

If $className defined in the same file, we can use it this way:

...
    $param = $request->getAttribute('param');

    $classInstance = new $classname();
    $output = $classInstance->$methodName($param);

    $response = new Zend\Diactoros\Response();
...

But if the class is defined in another file (e.g. a different namespace like Vendor\Controller\ClassName), how can I instantiate it?

Belkin
  • 199
  • 15

1 Answers1

1

The only way to use a class in Aura router is by either defining it within the controller or load the class by using the use statement at the top.

Belkin
  • 199
  • 15