symfony change url of object action - php

I have an object action approve and I'd like to change its url from /module/ListApprove/action?id=XXX to /module/:slug/approve. I have tried adding a route in routing.yml but no help. Also, I have ecexuteApprove defined in my action.
modified routing.yml:
poster_approve:
url: /poster/:slug/approve
params: {module: poster, action: approve}
poster:
class: sfDoctrineRouteCollection
options:
model: Poster
module: poster
prefix_path: /poster
column: slug
with_wildcard_routes: true
when I manually call /poster/someslug/approve, it works fine. But in the admin list interface, in the actions column, the url for approve is not /poster/someslug/approve , instead it is /poster/ListApprove/action?id=12.
After it I added an action parameter to my generator.yml like this:
object_actions:
_delete:
credentials: delete_poster
approve:
credentials: approve_poster
action: approve
but the only change this time is, the link url becomes /poster/approve/action?id=12. How do I change this?

How does your routing.yml action look like? You could add something like:
list_approve:
url: /someModule/:slug/:id
param: { module: someModule, action: approve }
Please define but no help, what problem are you encountering?

Related

masked own parameter in Symfony routing

If i will make own link in symfony:
http://www.mypage.com/phone/show/id/1
for:
http://www.mypage.com/linksone
in routing:
linksone:
url: /linksone
param: { module: phone, action: show, id: 1 }
what if i use own parameter in URL?
how example:
http://www.mypage.com/phone/show?number=3
i dont have change this link for
http://www.mypage.com/phone/show/number/3
i must use:
http://www.mypage.com/phone/show?number=3 - with /number/3 doesnt work.
is possible make routing with own parameter?
linksone:
url: /linksone
param: { module: phone, action: show, number: 3 }
doesnt work
This page in the "Practical Symfony" tutorial explains the routing in Symfony: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/05
You can introduce parameters in your URL like this:
linksone:
url: /phone/show/:number
param: { module: phone, action: show }
If you want to make the :number parameter optional, you can add the default value to the param option:
linksone:
url: /phone/show/:number
param: { module: phone, action: show, number: 1 }

Passing Delete Method Through sfGuard

I have an application with people and groups in Symfony, where a person may have a membership with multiple groups. To remove a person from a group, I currently have an action in a 'groupMembers' module that takes a 'delete' method and removes the pair from a many-to-many entity 'group_membership'. The route currently looks something like this:
remove_membership:
url: /group-membership/:group_id/:person_id
class: sfPropelRoute
options: { model: GroupMembership, type: object }
param: { module: groupMembers, action: remove }
requirements:
sf_method: [delete]
To perform this action, the user needs to be logged in, so I restricted it using sfGuard in the module's security.yml:
remove:
is_secure: true
So after clicking a 'remove' link, a user who isn't logged in is taken to the log in screen, but after clicking 'submit' the request is no longer a 'delete' but a 'get', meaning the similar add_to_group route is called instead!
add_to_group:
url: /group-membership/:group_id/:person_id
param: { module: groupMembers, action: create }
...
Is there any way to make sfGuard emulate a delete action and pass the parameters properly, or will I have to use a different route?
It seems that there is no way to achieve this without writing custom code or editing code of sfGuard plugin.
See plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php (its executeSignin method for details) how sign in is handled.
sfGuard gets user referrer and performs redirect with appropriate method of sfAction. This redirect is performed by using http header Location. So browser will use GET method to receive url content.
You can override default signin action and perform redirects from remove_membership route to an action which will use sfBrowser component to emulate POST request, but I highly recommend you to change routing scheme.

How to resolve url from query into route

I'm trying to find a way get the symfony 1.4 to render the page:
/detail/id/1
when url called is:
/?url=/detail/id/1
Any ideas? Been googling around but so far haven't found the solution for it. Any ideas? I know it could be done with rewrites but i hoped i can do it through routing.yml somehow.
You can manually add that line into your routing.yml, in your case I would do (i suppouse that the module is detail and the action is id):
detail_id:
url: /?url=/detail/id/:id
param: { module: detail, action: id }
requirements:
id: \d+
Getting the id from the action with $this->getParameter('id')

Passing Params to Symfony Routes

I have a defined route that displays a dynamic page:
page_show:
url: /:domain_slug/:slug
class: sfPropelRoute
options:
model: Page
type: object
method: doSelectByDomain
param: { module: page, action: show }
requirements:
sf_method: [get]
This works great, but now I want my homepage URI to route to a specific page. To do that, I assume that I have to pass the :domain_slug and :slug values of the page I want to display as the homepage. That's fine, but I can't seem to track down any documentation or example that shows me how to go about doing that.
Is it possible to specify specific variable values in a route? In this case, I want to pass :domain_slug => portal, :slug => dashboard (that syntax doesn't work, btw). Essentially, I want to create a homepage route that looks something like this:
homepage:
url: /
class: sfPropelRoute
param: { module: page, action: show, array( :domain_slug => portal, :slug => dashboard ) }
options:
model: Page
type: object
method: doSelectByDomain
But different enough that it, you know, works. :-) I suppose I could create a simple route to a different method, modify the request parameters manually and forward to the executeShow() method, but that's a hack I'd rather avoid if a more elegant solution is available.
Thanks.
You can define values in the param key of the route... for example:
homepage:
url: /
class: sfPropelRoute
param: { module: page, action: show, domain_slug: portal, slug: dashboard}
options:
model: Page
type: object
method: doSelectByDomain
At least thats how it works with a non propel/doctrine route. I assume it should be the same with any type of route in the framework.
I never found a way to do this that worked (or maybe I just couldn't manage to do it correctly). My solution was to create the route and pass it through a custom method that does the work to specify the appropriate page details:
homepage:
url: /
class: sfPropelRoute
options:
model: Page
type: object
method: doSelectHomepage
param: { module: page, action: show ) }
requirements:
sf_method: [get]
The doSelectHomepage() method does all of the work I was hoping I'd be able to do by hardcoding values in the route itself.
Actually it did work, it was just the order in which the routes were defined. The first answer is correct. It may have worked for you if you added "homepage" rule BEFORE the "page_show" rule. So maybe Symfony isn't as stupid as I thought...No, no, it is. It's just not that bad.

Can you force symfony resolve to a specific route?

Say that I have to following 2 routes in this order:
Zip:
url: home/:zip
param: { module: home, action: results }
State:
url: home/:state
param: { module: home, action: results }
and I use a route such as:
'#State?state=CA'
Why does it resolve to the Zip route?
I thought when you specified the route name explicitly: '#State' that it did not parse the entire routing file and just used the specific route you asked for.
I would like to be able to use the same action to display data based on the variable name (zip or state) I don't want to have to create the same action (results) twice just to pass in a different parameter.
You need to add requirements so that it will recognize the different formats
Zip:
url: home/:zip
param: { module: home, action: results }
requirements: { zip: \d{5} } # assuming only 5 digit zips
State:
url: home/:state
param: { module: home, action: results }
requirements: { state: [a-zA-Z]{2} }
That should fix it, although I agree with you that when you use a route name in a helper it should use the named route.
the problem here is that both routing rules resolves to somewhat same url ( /home/) and when generating links it uses correct named route to generate url.
when you click on that generated url( for example /home/CA) withouth requirements addition it will match the first rule in routing.yml file that matches and that is your "Zip" route.
just to explain what is happening.
It does use the named route. The issue is that your URLs are the same (the paramater name is irrelevant) so when you load the URL in your browser, the first route to match will always be Zip as there is no way for Symfony to know which one you want.
Adding requirements: is the way to go.

Categories