开发者

Zend View: Domain to Action

开发者 https://www.devze.com 2023-03-30 08:56 出处:网络
I am looking for a method in the bootstrap that looks at the URL then loads a specific module/controller/action.

I am looking for a method in the bootstrap that looks at the URL then loads a specific module/controller/action.

However I don't want the user to开发者_JAVA百科 see it.

Is this possible and easy?


I'm unsure wether you are looking for Hostname Routing, or just normal Routing, so I will answer both.

Zend_Controller_Router_Route

ie domain.com/users/layke

Using Zend_Controller_Route you can create a route will will grab "layke" and use that as a parameter. This would be a a standard Route.

$route = new Zend_Controller_Router_Route(
    'users/:username',
    array(
        'controller' => 'profile',
        'action'     => 'users'
    )
);
$router->addRoute('user', $route);

Then also there is hostname matching....

Zend_Controller_Router_Route_Hostname

For instance, (as the guides provide)...

You could use..

:username.domain.com to map to

/default/users/:username.

Zend_Controller_Router

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
    ':username.example.com',
    array(
        'controller' => 'profile',
        'action'     => 'users'
    )
);     
$plainPathRoute = new Zend_Controller_Router_Route_Static('');     
$router->addRoute('user', $hostnameRoute->chain($plainPathRoute));

Examples Documentation : Zend_Controller_Router


Sounds like you're after hostname routes: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname


You can use Routes in Zend (http://framework.zend.com/manual/en/zend.controller.router.html) and then mod_rewrite + .htacess for apache (http://httpd.apache.org/docs/current/mod/mod_rewrite.html) or the URL rewrite module in IIS (http://www.iis.net/download/URLRewrite)

These functions are "needed" for using Zend at all, as the URL mysite.com/demo1/demo2/ actually translates to something like mysite.com/index.php?controller=demo1?action=demo2

0

精彩评论

暂无评论...
验证码 换一张
取 消