Hostname routing query

4 messages Options
Embed this post
Permalink
Raavi Raaj

Hostname routing query

Reply Threaded More More options
Print post
Permalink
Hi,

Currently I have a route for static pages (e.g. about, terms, privacy, ...) like...

'static_path' => array(
        'type'  => 'Zend_Controller_Router_Route_Regex',
        'route' => 'pages(\/.+)?',
        'defaults' => array(
            'controller'      => 'static',
            'action'          => 'view'
        ),
        'map' => array(
            1                 => 'file'
        ),
        'reverse'              => 'pages/%s'
    ),

Which handles routes like...
domain.com/pages/about
domain.com/pages/help/someting
etc.

How can I use the hostname routing to achieve...
pages.domain.com/about
pages.domain.com/help/something

All help is appreciated.
-R

P.S. I tried to achieve it by reading the documentation but came up with no working solution :)

keith Pope-4

Re: Hostname routing query

Reply Threaded More More options
Print post
Permalink
You need to use the hostname route plus route chaining.

$actionRoute = new Zend_Controller_Router_Route(
    ':action/*',
    array(
        'action' => 'index'
    )
);

$route = new Zend_Controller_Router_Route_Hostname(
    ':username.domain.com',
    array(
           'controller' => 'account',
           'action' => 'index'
    ),
    array(
        'username' => '(?!.*www)[a-zA-Z-_0-9]+'
    )
);
$router->addRoute('account', $route->chain($actionRoute));

Hope this helps.

2008/12/8 Raavi Raaj <[hidden email]>:

> Hi,
>
> Currently I have a route for static pages (e.g. about, terms, privacy, ...)
> like...
>
> 'static_path' => array(
>         'type'  => 'Zend_Controller_Router_Route_Regex',
>         'route' => 'pages(\/.+)?',
>         'defaults' => array(
>             'controller'      => 'static',
>             'action'          => 'view'
>         ),
>         'map' => array(
>             1                 => 'file'
>         ),
>         'reverse'              => 'pages/%s'
>     ),
>
> Which handles routes like...
> domain.com/pages/about
> domain.com/pages/help/someting
> etc.
>
> How can I use the hostname routing to achieve...
> pages.domain.com/about
> pages.domain.com/help/something
>
> All help is appreciated.
> -R
>
> P.S. I tried to achieve it by reading the documentation but came up with no
> working solution :)
>
>



--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------
Raavi Raaj

Re: Hostname routing query

Reply Threaded More More options
Print post
Permalink
Hi,
 
I still don't understand this, sorry
 
I have a routes config file which provides an array to the addConfig method of the router like...
$router->addConfig(new Zend_Config($routes));
 
The route config file looks like...
return array(
//...
'static_path' => array(
        'type'  => 'Zend_Controller_Router_Route_Regex',
        'route' => 'pages(\/.+)?',
        'defaults' => array(
            'controller'      => 'static',
            'action'          => 'view'
        ),
        'map' => array(
            1                 => 'file'
        ),
        'reverse'              => 'pages/%s'
    ),
//...
}
 
Can you please help me modify the above route to enable routing like...
 
Where...
$file = '' or 
$file = 'about' or
$file = '/help/about-someting' etc.
 
Thanks again.
-R
 
On 12/8/08, keith Pope <[hidden email]> wrote:
You need to use the hostname route plus route chaining.

$actionRoute = new Zend_Controller_Router_Route(
   ':action/*',
   array(
       'action' => 'index'
   )
);

$route = new Zend_Controller_Router_Route_Hostname(
   ':username.domain.com',
   array(
          'controller' => 'account',
          'action' => 'index'
   ),
   array(
       'username' => '(?!.*www)[a-zA-Z-_0-9]+'
   )
);
$router->addRoute('account', $route->chain($actionRoute));

Hope this helps.

2008/12/8 Raavi Raaj <[hidden email]>:
> Hi,
>
> Currently I have a route for static pages (e.g. about, terms, privacy, ...)
> like...
>
> 'static_path' => array(
>         'type'  => 'Zend_Controller_Router_Route_Regex',
>         'route' => 'pages(\/.+)?',
>         'defaults' => array(
>             'controller'      => 'static',
>             'action'          => 'view'
>         ),
>         'map' => array(
>             1                 => 'file'
>         ),
>         'reverse'              => 'pages/%s'
>     ),
>
> Which handles routes like...
> domain.com/pages/about
> domain.com/pages/help/someting
> etc.
>
> How can I use the hostname routing to achieve...
> pages.domain.com/about
> pages.domain.com/help/something
>
> All help is appreciated.
> -R
>
> P.S. I tried to achieve it by reading the documentation but came up with no
> working solution :)
>
>



--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

keith Pope-4

Re: Hostname routing query

Reply Threaded More More options
Print post
Permalink
$pageRoute = new Zend_Controller_Router_Route(
   ':page/*',
);

$route = new Zend_Controller_Router_Route_Hostname(
   'pages.domain.com',
   array(
          'controller' => 'static',
          'action' => 'view'
   )
);
$router->addRoute('static_path', $route->chain($pageRoute));

Maybe something like that?

Check out the docs here:

http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname

2008/12/9 Raavi Raaj <[hidden email]>:

> Hi,
>
> I still don't understand this, sorry
>
> I have a routes config file which provides an array to the addConfig method
> of the router like...
> $router->addConfig(new Zend_Config($routes));
>
> The route config file looks like...
> return array(
> //...
> 'static_path' => array(
>         'type'  => 'Zend_Controller_Router_Route_Regex',
>         'route' => 'pages(\/.+)?',
>         'defaults' => array(
>             'controller'      => 'static',
>             'action'          => 'view'
>         ),
>         'map' => array(
>             1                 => 'file'
>         ),
>         'reverse'              => 'pages/%s'
>     ),
> //...
> }
>
> Can you please help me modify the above route to enable routing like...
> pages.domain.com
> pages.domain.com/about
> pages.domain.com/help/about-something
>
> Where...
> $file = '' or
> $file = 'about' or
> $file = '/help/about-someting' etc.
>
> Thanks again.
> -R
>
> On 12/8/08, keith Pope <[hidden email]> wrote:
>>
>> You need to use the hostname route plus route chaining.
>>
>> $actionRoute = new Zend_Controller_Router_Route(
>>    ':action/*',
>>    array(
>>        'action' => 'index'
>>    )
>> );
>>
>> $route = new Zend_Controller_Router_Route_Hostname(
>>    ':username.domain.com',
>>    array(
>>           'controller' => 'account',
>>           'action' => 'index'
>>    ),
>>    array(
>>        'username' => '(?!.*www)[a-zA-Z-_0-9]+'
>>    )
>> );
>> $router->addRoute('account', $route->chain($actionRoute));
>>
>> Hope this helps.
>>
>> 2008/12/8 Raavi Raaj <[hidden email]>:
>> > Hi,
>> >
>> > Currently I have a route for static pages (e.g. about, terms, privacy,
>> > ...)
>> > like...
>> >
>> > 'static_path' => array(
>> >         'type'  => 'Zend_Controller_Router_Route_Regex',
>> >         'route' => 'pages(\/.+)?',
>> >         'defaults' => array(
>> >             'controller'      => 'static',
>> >             'action'          => 'view'
>> >         ),
>> >         'map' => array(
>> >             1                 => 'file'
>> >         ),
>> >         'reverse'              => 'pages/%s'
>> >     ),
>> >
>> > Which handles routes like...
>> > domain.com/pages/about
>> > domain.com/pages/help/someting
>> > etc.
>> >
>> > How can I use the hostname routing to achieve...
>> > pages.domain.com/about
>> > pages.domain.com/help/something
>> >
>> > All help is appreciated.
>> > -R
>> >
>> > P.S. I tried to achieve it by reading the documentation but came up with
>> > no
>> > working solution :)
>> >
>> >
>>
>>
>>
>> --
>> ----------------------------------------------------------------------
>> [MuTe]
>> ----------------------------------------------------------------------
>
>



--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------