I've long wondered how to best support the zrl parameter within the Slim framework context. I was stuck for a while because I needed to find the intersection of the Request object that contains the query parameter, the Router to generate URLs for routes including the parameter, and the Renderer to append the parameter to external URLs (not handled by the internal router).
The solution was to use a midlleware class to extract the query string parameter from the request and store it as an attribute of the Renderer, then have the Router be a dependency of the Renderer, then write two Renderer helper methods to append automatically the zrl parameter to route URLs and external URLs repsectively.
Then I had to replace all the hard-coded URLs in the templates with either method calls.
In the end, it was easier than I initially expected, but it took me a while to wrap my head around the dependency injection philosophy I'm trying to use through Slim.
Closes #24
I've long wondered how to best support the
zrl
parameter within the Slim framework context. I was stuck for a while because I needed to find the intersection of the Request object that contains the query parameter, the Router to generate URLs for routes including the parameter, and the Renderer to append the parameter to external URLs (not handled by the internal router).The solution was to use a midlleware class to extract the query string parameter from the request and store it as an attribute of the Renderer, then have the Router be a dependency of the Renderer, then write two Renderer helper methods to append automatically the zrl parameter to route URLs and external URLs repsectively.
Then I had to replace all the hard-coded URLs in the templates with either method calls.
In the end, it was easier than I initially expected, but it took me a while to wrap my head around the dependency injection philosophy I'm trying to use through Slim.