English 中文(简体)
key value routing in Zend Framework Route
原标题:

I m using a Hostname route to capture a subdomain and use as a category. I then chain a Router route for the controller, action and key/value pairs.

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
  :customer.ddc.:domain ,
 array(
   customer  =>  :customer 
 )
);

$routerRoute = new Zend_Controller_Router_Route(
  :controller/:action/* ,
 array(
   controller  =>  index ,
   action  =>  index 
)
);
$chainedRoute = $hostnameRoute->chain($routerRoute);
$frontController->getRouter()->addRoute( default ,$chainedRoute);

I can capture everything except the key/value pairs on the URI. Adding them causes the Params object in the Request to not get populated.

This works: http://category.mydomain.com/controller/action/

This does not: http://category.mydomain.com/controller/action/username/frank

Thanks for any suggestions.

最佳回答

There is indeed a bug which prevents wildcard matching when chaining routes. The comments in the bug description were very helpful in solving this issue with just a few lines of code change.

framework.zend.com/issues/browse/ZF-6654

问题回答

Try to use without /*.

$routerRoute = new Zend_Controller_Router_Route(
     :controller/:action ,
    array(
         controller  =>  index ,
         action      =>  index 
    )
);

as in 12.5.2. Using a Router is described.

The suggested patch didn t work for me. I adapted another patch found elsewhere on the ZF website and it seems to work well: http://pastie.org/1815135





相关问题
Rails: Proxy Pass?

I ve got a web-app that I want to migrate to Rails, which is currently just plain HTML with an Apache proxy to another server, running a custom database/webserver that serves the site s dynamic ...

MVC routing is not handling one of my directories

I m using ASP.NET MVC with IIS 7.0. I ve got 404 errors hooked up fine through my Application_Error override. In addition to "Controllers", "Models", "Helpers" etc. I have a directory called Files ...

Ruby on Rails conditional routing

I have a site listing many jobs, but I also want each account to be able to access its jobs in one place. Thus, I am using these routes: map.resources :jobs map.resource :account, :has_many => :...

Clean URL s using OpenCart s router class

How do you write clean URL s in OpenCart using their built in Router class? Here is my .htaccess file: RewriteEngine On RewriteRule ^(system) - [F,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...

subdomain routing to multiple controller issue

I have a site: www.mydomain.com where we have administrative controls hidden away from normal customer view. I would like to only access the administrative features under a subdomain such as admin....

Can controller names in RESTful routes be optional?

With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/...

Help with rails routes

Im having a little trouble setting up routes. I have a users controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be usuarios ...

热门标签