You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just an idea, to have routes assigned to variables to make routes more dynamic.
I come up with this while was changing bunch of same URLs in the twig template.
Let's say we have this route with 3rd argument as a variable: $router->add('posts/index', ['controller' => 'Posts', 'action' => 'index'],'post_index');
We can then pass it the same way as route_params to the controller and in addition create a global twig variable (called routes) so it can be accessed from the view.
and instead of having this in twig: <a href="{{ URL }}posts/index">Test</a>
We could have: <a href="{{ URL }}{{ routes.post_index }}">Test</a>
Which after render would give <a href="https://website.com/posts/index">Test</a>
With this solution we'd need only change route in one place, instead of going through bunch of files.
I haven't thought of implementation of it yet though, so if I come up with something - will let you know
The text was updated successfully, but these errors were encountered:
Just an idea, to have routes assigned to variables to make routes more dynamic.
I come up with this while was changing bunch of same URLs in the twig template.
Let's say we have this route with 3rd argument as a variable:
$router->add('posts/index', ['controller' => 'Posts', 'action' => 'index'],'post_index');
We can then pass it the same way as route_params to the controller and in addition create a global twig variable (called routes) so it can be accessed from the view.
and instead of having this in twig:
<a href="{{ URL }}posts/index">Test</a>
We could have:
<a href="{{ URL }}{{ routes.post_index }}">Test</a>
Which after render would give
<a href="https://website.com/posts/index">Test</a>
With this solution we'd need only change route in one place, instead of going through bunch of files.
I haven't thought of implementation of it yet though, so if I come up with something - will let you know
The text was updated successfully, but these errors were encountered: