Sending in prepared data for link generation
Notice: This thread is very old.
- tomolas
- Member | 66
Hello,
imagine you have a route in format: users/1234-john-doe
Router would look something like this:
<?php
$routes[] = new Route('users/<user_id>', array(
'module' => 'Front',
'presenter' => 'User',
'action' => 'profile',
'user_id' => array(
Route::FILTER_OUT => callback('UrlResolver::idToUrl'),
Route::FILTER_IN => callback('UrlResolver::urlToId')
)
), $default_flags);
?>
When creating a link, UrlResolver
goes and looks inside the
database (e.g. to find users name by user id).
In the moment of link creation, I actually often have users name already available in a variable inside a template. My goal is to skip the database query and construct the link with data already provided.
It could look something like this:
<?php
Visit a profile of:
<a href="{link User:profile ['user_id' = 1234, 'name' => 'John Doe']}">John Doe</a>
// would link to: /users/1234-john-doe
?>
..the problem is, that $name
is not accessible/passed inside the
UrlResolver
method calls.
How do I accomplish this?
Maybe I'm missing something obvious.
Thank you for your help.
Last edited by tomolas (2017-03-02 23:16)