hello,
i have this
->add('graph', 'url', array(
'route' => array(
'name' => 'graphs',
'parameters' => array('member_id' => 'member_id'),
'identifier_parameter_name' => 'id'
),
'label' => 'graph',
))`
where id is identificator from campaigns table, in this table i have also column member_id and i need pass it to route It is this possible in ListFields?
This is an "old" feature that is not there unfortunately. You can find a SO question asked in mid 2014.
I encountered this on my own, and the way to overcome this for me was assigning a custom template for that mapped field only.
But, reading the doc there is a route.parameters option. The way it works right now is with fixed param values.
I think it would be better to make this option a little more dynamic, something like :
->add('title', 'url', array(
'route' => array(
'name' => 'acme_blog_article',
'absolute' => true,
'parameters' => array(
'format' => 'xml', // fixed value params
'member_id' => 'getMemberId' // set the getter name
),
'identifier_parameter_name' => 'id'
)
))
This makes it more intuitive (_human wise_), but needs extra check in the template if we have a getter or fixed value.
Another way would be to add a separate option similar to identifier_parameter_name which you list all param names and their associated field.
->add('title', 'url', array(
'route' => array(
'name' => 'acme_blog_article',
'absolute' => true,
'parameters' => array('format' => 'xml'),
'identifier_parameter_name' => 'id',
'object_parameters' => array ('member_id' => 'getMemberId'), // Not sure about the name here
)
))
This way is a little less intuitive but lowers template complexity. @OskarStark What do you think?
i would prefer option 1 as both are parameters, but its hard to find out which of both is a callback, and which is a hardcoded value, if we would use the property accessor, this could fail if a getXml-method exists... :(
@core23 @rande what do you think?
I would prefer another option:
->add('title', 'url', array(
'route' => array(
'name' => 'acme_blog_article',
'absolute' => true,
'parameters' => array(
'format' => 'xml', // fixed value params
'member_id' => function($object) {
return $object->getId();
},
),
'identifier_parameter_name' => 'id'
)
))
In the face of ambiguity, refuse the temptation to guess
So option 2.
馃憤
Is this added yet? Just wondering to go with template or to upgrade and use this?
For anyone who needs this asap: https://gist.github.com/Padam87/835a7025635d5ebc712421a50eec89d7
@stivenllupa what do you think about the solution of @Padam87
It's looks very useful! Are there some updates about passing dynamic parameters to a route in ListFields?
Was this finally added or is there any other way to create a url for relation model?
For example, I want in my ArticleAdmin::configureListFields() to create a link to edit the category of the article. I need the ID of the category. Each article has a category: $article->getCategory().
How to grab the category.id knowing that 'identifier_parameter_name' => 'id' is the ID of $article?
->add('category.name', 'url', [
'route' => [
'name' => 'admin_app_category_edit',
'parameters' => [
'id' => 'category.id'
]
]
])
Thanks
Why whatever value I use, I get string as 'category.id' in my url ("http://mysite/app_dev.php/admin/user/category/category.id/edit")? With closure in id parameter I get "An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Closure could not be converted to string")."
$listMapper
->add('office.category',
'url', array(
'admin_code' => 'user.admin.category',
'route' => [
'name' => 'admin_office_category_edit',
'absolute' => true,
'parameters' => [
'id' => function($object) {
return $object->getId();
},
// 'id' => 'category.id'
],
]
))
Lets continue this one in #4733 . They look like the same issue, so Im closing this one.
If they are not the same, please ping me to reopen. I am just trying to cleanup duplicates
i think it is not a same, because in that issue they are talking about using parameter which is not entity id.
In this issue we are talking about using 2 different parameters.
Both are talking about generating urls with parameters that come from the entity, without the limitation of being only for the id. Right?
yes you are right :)
Most helpful comment
I would prefer another option: