This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.0 » dynamic routing
dynamic routing [message #102917] Thu, 22 July 2010 09:06 Go to next message
gaurangrajvir  is currently offline gaurangrajvir
Messages: 156
Registered: May 2007
Location: RAJKOT
Senior Member
Hi


currently i have 3 different url according to parameter

http://www.example.com/gview/animals1

http://www.example.com/gview/animals/pets/2

http://www.example.com/gview/animals/pets/food/3


some time there are no category and section available in parameter.
and type and id is always available.
so i m handling all this by below routing rule.

routing.yml
-------------------------
type:
  url:   /gview/:type/:id
  param: { module: home, action: view}
  requirements:  { id: \d+ }
  
category:
  url:   /gview/:type/:category/:id
  param: { module: home, action: view}
  requirements:  { id: \d+ }
  
section:
  url:   /gview/:type/:category/:section/:id
  param: { module: home, action: view}
  requirements:  { id: \d+ }



In template i have written like below

*Success.php
----------------------
if(section){
	echo link_to('Link Name','@section?type=animal&category=pets&section=foods&id=3');
}elseif(category){
	echo link_to('Link Name','@category?type=animal&category=pets&id=2');
}else{
	echo link_to('Link Name','@section?type=animal&id=1');
}


so for all above i need to write condition everywhere to make different link according to routing rule.

is it possible to handle all with one routing rule ?

Thanks in advance

- Gaurang


Re: dynamic routing [message #102989 is a reply to message #102917 ] Fri, 23 July 2010 11:47 Go to previous messageGo to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
What about using default values in your routing:

section:
  url:   /gview/:type/:category/:section/:id
  param: { module: home, action: view, category: 'empty', section: 'empty'}
  requirements:  { id: \d+ }


and then let executeView find out if category and/or section is given.


May the source be with you
Re: dynamic routing [message #102990 is a reply to message #102989 ] Fri, 23 July 2010 11:58 Go to previous messageGo to next message
gaurangrajvir  is currently offline gaurangrajvir
Messages: 156
Registered: May 2007
Location: RAJKOT
Senior Member
Yes it will work but in url there is 'empty' text if not category or section exist...

and also need to write three condition in success file

like below

if(section){
	echo link_to('Link Name','@section?type=animal&category=pets&section=foods&id=3');
}elseif(category){
	echo link_to('Link Name','@category?type=animal&category=pets&id=2');
}else{
	echo link_to('Link Name','@section?type=animal&id=1');
}


i have found one. but it is request not working currently...

http://trac.symfony-project.org/ticket/2478

thanks for reply...

- Gaurang

Re: dynamic routing [message #102992 is a reply to message #102990 ] Fri, 23 July 2010 12:21 Go to previous messageGo to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
I know that the 'emtpy' part will be displayed in the URL... but I don't consider that as a problem.

What you would have to think about is that the string 'empty' cannot be something valid.


May the source be with you
Re: dynamic routing [message #103023 is a reply to message #102992 ] Sat, 24 July 2010 05:55 Go to previous messageGo to next message
gaurangrajvir  is currently offline gaurangrajvir
Messages: 156
Registered: May 2007
Location: RAJKOT
Senior Member
Actually we know the condition why that is display...

but client dont want to display that...that's why...Sad


Thanks for reply

- Gaurang
Re: dynamic routing [message #103025 is a reply to message #103023 ] Sat, 24 July 2010 09:26 Go to previous messageGo to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
If your client does not want it, then you already got the solution - three different routings.


May the source be with you
Re: dynamic routing [message #103068 is a reply to message #103025 ] Mon, 26 July 2010 06:22 Go to previous message
gaurangrajvir  is currently offline gaurangrajvir
Messages: 156
Registered: May 2007
Location: RAJKOT
Senior Member
yes, but want to confirm if any other way for the same things..


thanks for reply

-Gaurang
Previous Topic:Template not shown in IE 6
Next Topic:Symfony 1.0 and Oracle 8i
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software