使用Zend_Controller_Router_Route_Hostname在多个域上运行相同的Zend_Framework站点

vdr*_*mrt 6 php zend-framework zend-controller-router

我需要运行基于zend_framework的同一站点才能在多个域上运行,我的应用程序需要知道它运行在哪个域上.我认为使用Zend_Controller_Router_Route_Hostname是个好主意,但我遇到了一些问题.

我的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));
Run Code Online (Sandbox Code Playgroud)

我收到以下错误"未指定子域".我想我在我的布局文件中跟踪它的$ this-> url是在路由与请求url匹配之前使用已定义的路由来汇编url​​.如果我将默认值设置为主机名路由,则不会收到错误,但布局中的URL使用默认值而不是当前主机名中的值.

谁能帮我解决这个问题?

cnk*_*nkt 1

您应该为子域定义默认值。将 $ 更改defaultRoute为:

$defaultRoute = new Zend_Controller_Router_Route(
    ':controller/:action/*',
    array(
        'controller' => 'index',
        'action' => 'index'
    )
);
Run Code Online (Sandbox Code Playgroud)

它应该有效。