2008年9月12日星期五

Re: [fw-mvc] How to use hostnames within zend router properly

Thanks for your help! Your blog post was a good read and helped me quite a bit.

On Wed, Sep 10, 2008 at 8:15 PM, Tom Graham <tom.graham@jadu.co.uk> wrote:
> Hi Pieter,
>
> You might want to take a look at a post on my blog:
> http://www.noginn.com/2008/09/03/using-subdomains-as-account-keys/
>
> The new route chaining might be what you are after, if I understood your
> e-mail correctly.
>
> Here is a snippet from my post:
>
> $pathRoute = new Zend_Controller_Router_Route(
> ':controller/:action/*',
> array(
> 'controller' => 'index',
> 'action' => 'index'
> )
> );
>
> $accountRoute = new Zend_Controller_Router_Route_Hostname(
> ':account.myapp.com',
> array(
> 'module' => 'account',
> ),
> array(
> 'account' => '([a-z0-9]+)',
> )
> );
> $router->addRoute('account', $accountRoute->chain($pathRoute));
>
> Hope that helps,
>
> Tom
>
>
> On 10 Sep 2008, at 17:18, Pieter wrote:
>
>> Hi everyone!
>> I hope someone can help me with this little problem. I am trying to
>> create 4 (almost identical) websites with the same backend. Each
>> website is located at a different subdomain (but the same domain).
>> I read in the ZF documentation that you can use hostname detection in
>> Zend router to map each subdomain.
>> I've tried the following code, directly from the ZF documentation:
>>
>> $route = new Zend_Controller_Router_Route(
>> array(
>> 'host' => 'blog.mysite.com',
>> 'path' => 'archive'
>> ),
>> array(
>> 'module' => 'blog',
>> 'controller' => 'archive',
>> 'action' => 'index'
>> )
>> );
>> $router->addRoute('archive', $route);
>>
>> But that'll give a array to string conversion error. So I guess the
>> documentation isn't perfect just yet ;-)
>> Then I tried:
>>
>> site.type = "Zend_Controller_Router_Route_Hostname"
>> site.route = "info.domain.com"
>> site.defaults.site = info
>> site.defaults.module = site
>> site.defaults.controller = index
>> site.defaults.action = index
>>
>> This works great. The problem is, however, that none of the automatic
>> route mapping (e.g. http://info.domain.com/signup to
>> controller=signup, action=index) work anymore as the rule above
>> overrides any other. If I define another rule, it will override the
>> hostname mapping and I will lose the parameter 'site'.
>>
>> So, what I would like to have is hostname mapping independent of any
>> other url mapping.
>>
>> Does anyone know how to solve this?
>>
>> Thanks for helping!
>>
>> p.s. I am using Zend Framework 1.6.0
>>
>
>

没有评论: