Using pathFor in php-view (PhpRenderer)

Is it possible to use pathFor inside a template that is rendered with php-view/PhpRenderer? I can’t seem to find it anywhere…

You can pass in the Router instance as a template variable and then call pathFor on that instance. You can find an example in the tutorial code.

To pass in the “router” variable (see code):

$response = $this->view->render($response, "tickets.phtml", ["tickets" => $tickets, "router" => $this->router]);

From there on you can call the pathFor method on the $router variable (see code):

<a href="<?php print $router->pathFor('ticket-detail', ['id' => $ticket->getId()])?>">view</a>

Thanks for the suggestion. I fixed my problem by adding the router to the attributes of the PhpRenderer object at creation-time (in dependencies.php), so it is available in all my templates.