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 }
Related
I want to migrate an older extension to Typo3 9.5. and wonder how to configure optional URL parameters.
Using 'defaults' allows to leave out parameters at the end, but how do I allow to leave out parameters in the middle, like example.com/filter//foo/bar or example.com/filter/foobar//bar.
This is my site configuration. It works well with parameters.
routeEnhancers:
filter:
type: Plugin
routePath: '/filter/{param0}/{param1}/{param2}'
namespace: 'tx_myextension_myplugin'
defaults:
param0: ''
param1: ''
param2: ''
aspects:
param0:
type: MyValueMapper
param1:
type: MyValueMapper
param2:
type: MyValueMapper
It is not an Extbase extension, so the controller works like this. In real I have some more params.
class MyController extends ActionController{
public function filterAction() {
// $this->request->getArgument('param0');
// $this->request->getArgument('param1');
// $this->request->getArgument('param2');
}
}
With symfony 1.4 I'm using this rule:
asasds:
url: /users/:order
param: { module: users, action: index }
I want to achieve this: www.mysite.com/users/aNumericValueAsOrder so far it looks ok, but what if I have an action www.mysite.com/users/createOrder as FORM POST action. createOrder() is a method, not an numeric id.
How to distinguish? How to tell it to the routing system that "please check whether it is an action"?
Try this:
asasds:
url: /users/:order
param: { module: users, action: index }
requirements: { order: \d+ }
That's for numeric values, of course; the requirements subparams are regular expressions, so are very flexible.
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?
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.
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.