Sending in prepared data for link generation

23 days ago

tomolas
Member | 67
+
0
-

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)

23 days ago

David Matějka
Moderator | 4735
+
0
-

23 days ago

tomolas
Member | 67
+
0
-

Thank you.. this seems to be available since Nette 2.1. (Not our case yet)
Also an example would be very helpful here, but thank you anyway.

Board footer

Terms and conditions