使用 Zend_Controller_Router_Route_Hostname 在多个域上运行相同的 Zend_Framework 站点
我需要基于 zend_framework 运行同一站点以在多个域上运行,并且我的应用程序需要知道它在哪个域上运行。 我认为使用 Zend_Controller_Router_Route_Hostname 是个好主意,但我遇到了一些问题。
我的引导程序中有以下代码,
$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();
$router->removeDefaultRoutes();
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':sub-domain.:domain.:tld'
);
$defaultRoute = new Zend_Controller_Router_Route(
':controller/:action/*',
array(
'controller' => 'index',
'action' => 'index'
)
);
$router->addRoute('default',$hostnameRoute->chain($defaultRoute));
但出现以下错误“未指定子域”。 我认为我跟踪到布局文件中的 $this->url 在路由与请求 url 匹配之前使用定义的路由来组装 url。 如果我为主机名路由设置默认值,我不会收到错误,但布局中的 url 使用默认值而不是当前主机名中的值。
谁能帮我解决这个问题?
I need to run the same site based upon the zend_framework to run on multiple domains and my application needs to be aware on which domain it is running on.
I thought it was a good idea to use Zend_Controller_Router_Route_Hostname, but I have run into some problems.
I have the following code in my bootstrap
$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();
$router->removeDefaultRoutes();
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':sub-domain.:domain.:tld'
);
$defaultRoute = new Zend_Controller_Router_Route(
':controller/:action/*',
array(
'controller' => 'index',
'action' => 'index'
)
);
$router->addRoute('default',$hostnameRoute->chain($defaultRoute));
I get the following error "sub-domain is not specified."
I think I tracked it down to that $this->url in my layout file is using the defined routes to assemble the url before the route is matched against the request url.
If I set default values to the hostname route I don't get the error but the urls in the layout use the default values instead of the values in the current hostname.
Who can help me solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该为子域定义默认值。将 $
defaultRoute
更改为:它应该可以工作。
You should define a default for subdomain. Change $
defaultRoute
to this:It should work.
您在 URL 生成中遇到了问题。您应该为主机名的路由定义中的变量指定参数,如下所示:
否则 Zend URL 助手无法为您的定义生成 url
:子域.:域.:tld 。提供的示例将生成此 url:
your-subdomain-here.your-domain.com/current_controller/current_action
还要检查子域是否是合法的变量名称。尝试将其更改为子域。
You've got a problem in URL generation. You should specify parameters for variables in route definition for your hostname like this:
Otherwise Zend URL helper can't generate url for your definition
:sub-domain.:domain.:tld . Provided example will generate this url:
your-subdomain-here.your-domain.com/current_controller/current_action
Also check if sub-domain is legal variable name. Try to change it to subdomain.