繁体   English   中英

如何将对www.example.com/admin的请求重定向到Zend中的其他模块

[英]How to redirect requests to www.example.com/admin to different module in Zend

我在应用程序中重定向请求时遇到问题。

我的规则:

  • loyer.domain.com-应指向雇主的页面-使用默认模块
  • loyer.domain.com/panel/-应指向特定雇主的管理页面-使用仪表板模块
  • www.domain.com-应指向汇总所有雇主的页面-使用默认模块

我已经测试了许多不同的路线,但是当一条路线有效时,另一条路线就坏了。 通常,它通常仅适用于根路径,但是当我添加对某些控制器和动作的调用时,它会崩溃。 也许我应该编写自定义控制器插件? 你怎么看?

这是我当前的配置。 这是一团糟,但也许会有助于捕获一些愚蠢的错误。

// employer.domain.com/panel
$pathRoute_panel = new Zend_Controller_Router_Route(
    ':panel/:controller/:action/:id/',
    array(
        'panel' => '',
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index',
        'id' => '',
    ),
    array(
        'panel' => 'panel'
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));


// employer.domain.com - main employer page
$pathRoute_panel = new Zend_Controller_Router_Route(
    '',
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));


// domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'index',
    ),
    $dispatcher,
    $request
);

$route = new Zend_Controller_Router_Route_Hostname($config['host']);
$router->addRoute('default', $route->chain($pathRoute));

// www.domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'index',
    ),
    $dispatcher,
    $request
);

$route = new Zend_Controller_Router_Route_Hostname('www.'.$config['host']);
$router->addRoute('default_www', $route->chain($pathRoute));

编辑:这是我的解决方案:

// employer.domain.com
$pathRoute_panel = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));

// employer.domain.com/panel/
$pathRoute_panel = new Zend_Controller_Router_Route(
    'panel/:controller/:action/:id/',
    array(
        'panel' => 'panel',
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));
// Enforce Subdomain usage
// Will match employer.domain.com/*
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    'employer.'.$config['host'] . '/*'
);


// Will match /panel/{id, required}/{controller, optional}/{action, optional}/{further parameters, optional}
$pathRoute_panel = new Zend_Controller_Router_Route(
    'panel/:id/:controller/:action/*',
    array(
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index'
    ),
    array(
        'id' => '\d+'
    )
);

// employer.domain.com - main employer page
// will match everything not matched before!
$pathRoute_page = new Zend_Controller_Router_Route(
    '*',
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index'
    )
);

// You can add several routes to one chain ;) The order does matter.
$subDomainRoute->chain($pathRoute_page);
$subDomainRoute->chain($pathRoute_panel);
$router->addRoute($subDomainRoute);

注释在代码中。 您可以使用通配符(*)来进一步匹配任何内容! 不需要default_www路由-这只是默认行为(默认路由现在将与每个子域匹配,但雇主会与subDomainRoute匹配)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM