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 » development » Feature requests » "host" key added to routing.yml?
"host" key added to routing.yml? [message #25553] Thu, 12 April 2007 15:47 Go to next message
sbabineau  is currently offline sbabineau
Messages: 23
Registered: April 2007
Junior Member
I posted about it here. How hard would this be to implement?

http://www.symfony-project.com/forum/index.php/t/5994/

This is how I see it:

profile_view:
  url:   /:username
  host:  /^(www)?\.domain\.com/
  param: { module: family, action: view }

group_view:
  url:   /:groupname
  host:  /^(www)?(^\.+)\.domain\.com/
  param: { module: family, action: view, hostkeys: street }
  # $this->getRequestParameter('street') should equal whatever came out from the "(^\.+)" regex token.


This would allow the routing.yml to be cached and be dynamic enough to support anything, including subdomains, that I threw at it.
Re: "host" key added to routing.yml? [message #25558 is a reply to message #25553 ] Thu, 12 April 2007 16:42 Go to previous messageGo to next message
sbabineau  is currently offline sbabineau
Messages: 23
Registered: April 2007
Junior Member
...Still thinking this through.

there would also need to be a way for helper functions like link_to to generate a URL. Specifically, if I were browsing at http://subdomain1.domain.com/group/messages, and I wanted a Signin link always point to http://domain.com/signin, the @signin routing rule should know that.

I don't know what the best way to implement this is, but what about something like this:

myapp/config/routing.yml
signin:
  url:   /signin
  host:  domain.com  #no wildcards means this is required for reverse linking
  param: { module: sfUserAuth, action: signin }

user_view:
  url:    /:username
  host:  /^(www)?\.(.+$)/  # means that the host can be www.domain.com or domain.com
  param: { module: profile, action: view }
  
family_view:
  url:   /:family
  host:  /^((?:(?:[^\.]+)?))\.(.+$)/  # means that the host can be anything.domain.com
  host_matches: { familygroup: 1 }
  param: { module: family, action: view }


maybe with code like this in sfRoutingConfigHandler (I do not know enough about sfRoutingConfigHandler to write real code for it yet. Consider this psuedo code):

public function getMatchingRule()
{
  if (preg_match($rule['host'], $req->getHost(), $matches))
  {
    if (count($matches) > 1)
    {
      // this rule matched
      foreach ($rule['host_matches'] as $k => $v)
      {
        $this->setRequestParameter($k, $matches[$v]);
      }
    }
    else
    {
      // didn't match.. move onto next rule
    }
  }
}

public function getUrlForRule($rulename)
{
  $rule = Rules::getByRuleName($rulename);
  if ($rule['host'])
  {
    if (substr($rule['host'], 0, 1) == '/')
    {
      // host isn't a regex, force it
      return 'http://' . $rule['host'] . '/' . $extra_path_stuff;
    }
    else if (preg_match($rule['host'], $req->getHost(), $matches))
    {
      // do some mumbo jumbo to parse the parameters and such to make the URL.  The important part is the current host matches the rule host
    }
    else
    {
      // doesn't match. return something incorrect
    }
  }
  else
  {
    // no host in the rule.. make the url relative
    return '/' . $extra_path_stuff;
  }
}


then in my code
// current url is 
http://subdomain1.domain.com/family
echo link_to('@family_view?family=babineau')
=> http://subdomain1.domain.com/babineau

// current url is 
http://subdomain1.domain.com/family
echo link_to('@signin')
=> http://domain.com/signin

Re: "host" key added to routing.yml? [message #25560 is a reply to message #25558 ] Thu, 12 April 2007 17:16 Go to previous messageGo to next message
cblin  is currently offline cblin
Messages: 265
Registered: July 2006
Faithful Member
Is not mod_rewrite done for that kind of thing ?

I mean what you want to do is to rewrite
www.street.domain.com/mymodule/myaction to domain.com/mymodule/myaction/street
www.forest.domain.com/mymodule/myaction to domain.com/mymodule/myaction/forest

then you have a routing.yml where you match your "host":
myrule:
  url: /:module/:action/:host


Or am I misunderstanding your need ...
Re: "host" key added to routing.yml? [message #25563 is a reply to message #25560 ] Thu, 12 April 2007 17:44 Go to previous messageGo to next message
sbabineau  is currently offline sbabineau
Messages: 23
Registered: April 2007
Junior Member
No, I don't think mod_rewrite will work because I do not want "mymodule/myaction/" in the URL that the user sees, nor do I want to add a mod_rewrite rule for every "street"

Basically I want these URL scenarios to parse out correctly:

http://mystreet.domain.com/myfamily => family/view, getRequestParameter('street')='mystreet', getRequestParameter('family')='myfamily'

http://www.domain.com/myuser => profile/view, getRequestParameter('username')='myuser'

http://domain.com/myuser => profile/view, getRequestParameter('username')='myuser'

http://domain.com/profile => profile/dashboard
http://www.domain.com/profile => profile/dashboard

http://mystreet.domain.com/myfamily/dashboard => family/dashboard, getRequestParameter('street')='mystreet', getRequestParameter('family')='myfamily'

then also, I would like

url_for('@signon', true) => http://domain.com/signon EVEN IF I am currently browsed to http://mystreet.domain.com/myfamily (ideally, I shouldn't need the second parameter. symfony and the routing should just know that I am currently not at the correct host so it needs to be absolute.)

Can I do all that with mod_rewrite without exposing URLs like http://domain.com/street/mystreet/family/myfamily/messageboa rd ?

[Updated on: Thu, 12 April 2007 17:46]

Re: "host" key added to routing.yml? [message #25603 is a reply to message #25558 ] Fri, 13 April 2007 05:09 Go to previous messageGo to next message
sbabineau  is currently offline sbabineau
Messages: 23
Registered: April 2007
Junior Member
sbabineau wrote on Thu, 12 April 2007 16:42


myapp/config/routing.yml
signin:
  url:   /signin
  host:  domain.com  #no wildcards means this is required for reverse linking
  param: { module: sfUserAuth, action: signin }

user_view:
  url:    /:username
  host:  /^(www)?\.(.+$)/  # means that the host can be www.domain.com or domain.com
  param: { module: profile, action: view }
  
family_view:
  url:   /:family
  host:  /^((?:(?:[^\.]+)?))\.(.+$)/  # means that the host can be anything.domain.com
  host_matches: { familygroup: 1 }
  param: { module: family, action: view }




Still thinking it through...

Maybe the regex piece is overkill and just making it more complicated than need-be. What about if you were to use the same pattern matching and substitution that you do the the url: key, only instead of the tokens being separated by /'s, they are separated by .'s.

Like this:

myapp/config/routing.yml
signin:
  url:   /signin
  host:  domain.com
  param: { module: sfUserAuth, action: signin }

user_view_www:
  url:    /:username
  host:   www.domain.com
  param: { module: profile, action: view }

user_view:
  url:    /:username
  host:   domain.com
  param: { module: profile, action: view }
  
family_view_www:
  url:   /:family
  host:  www.:familygroup.domain.com
  param: { module: family, action: view }

family_view:
  url:   /:family
  host:  :familygroup.domain.com
  param: { module: family, action: view }

# any host goes
any_domain_rule:
  url:   /*
  param: { module: default, action: index }



Something like this isn't much more complicated to code for than what is already in place AND it maintains reverse lookup capability AND it is simple enough for the user (me) to code for.

I could make my own routing parsing class that would do this, but all the existing helpers won't use it, otherwise I would have done it by now. Is there some way to make this change in the code and have the URL helpers to use it automatically?
Re: "host" key added to routing.yml? [message #77676 is a reply to message #25553 ] Sun, 03 May 2009 06:14 Go to previous messageGo to next message
zzzrByte  is currently offline zzzrByte
Messages: 22
Registered: March 2006
Location: Israel
Junior Member
Check out sfDomainRoutePlugin.

I wrote it specifically for dealing with different subdomains, and I think it can provide a solution to what you're trying to accomplish here.

Check it out, and let me know if it helps.

[Updated on: Sun, 03 May 2009 06:33]


Tal Ater
http://www.GreenAnySite.com/
Re: "host" key added to routing.yml? [message #78265 is a reply to message #25553 ] Wed, 13 May 2009 14:07 Go to previous message
mosez  is currently offline mosez
Messages: 28
Registered: May 2008
Location: Nuremberg
Junior Member

But for that you got to split up the routing file into environments too. For developing most people got a separate domain then the prod version...
Previous Topic:Use events to clear some selective parts of the cache
Next Topic:MoxieCode (tinyMCE) image/filemanager auth integration class attached
Goto Forum:
  

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