前两天 我正在与泽德框架路线者交战,但仍未找到解决办法。
现有项目有2个不同的模块,它们与同一领域(例如)合作。
- default - Contains public information, can be accessed via www.domain1.com
- admin - Administrator interface, can be accessed via www.domain1.com/admin
项目是多兰的,为了保持语言代码,它作为每个URL的第一个参数传输,例如www.domain1.com/en/www.domain1.com/en/admin/strong>。
Part of code which takes care is next plugin:
class Foo_Plugin_Language extends Zend_Controller_Plugin_Abstract
{
const LANGUAGE_KEY = lang ;
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$languagesRegexp = implode( | , array_map( preg_quote , $this->_bootstrap->getLanguages()));
$routeLang = new Zend_Controller_Router_Route(
: . self::LANGUAGE_KEY,
array(self::LANGUAGE_KEY => $this->_bootstrap->getLanguage()->toString()),
array(self::LANGUAGE_KEY => $languagesRegexp)
);
$router = $this->getFrontController()->getRouter();
$router->addDefaultRoutes();
$chainSeparator = / ;
foreach ($router->getRoutes() as $name => $route) {
$chain = new Zend_Controller_Router_Route_Chain();
$chain
->chain($routeLang, $chainSeparator)
->chain($route, $chainSeparator);
$new_name = $this->_formatLanguageRoute($name);
$router->addRoute($new_name, $chain);
iii
protected function _formatLanguageRoute($name)
{
$suffix = _ . self::LANGUAGE_KEY;
if (substr($name, -strlen($suffix)) == $suffix) return $name;
return $name . _ . self::LANGUAGE_KEY;
iii
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$lang = $request->getParam(self::LANGUAGE_KEY, null);
$this->_bootstrap->setLanguage($lang);
$actual_lang = $this->_bootstrap->getLanguage()->toString();
$router = $this->getFrontController()->getRouter();
$router->setGlobalParam(self::LANGUAGE_KEY, $lang);
// Do not redirect image resize requests OR get js, css files
if (preg_match( /.*.(jpg|jpeg|gif|png|bmp|js|css)$/i , $request->getPathInfo())) {
return true;
iii
// redirect to appropriate language
if ($lang != $actual_lang) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper( redirector );
$params = array(self::LANGUAGE_KEY => $actual_lang);
$route = $this->_formatLanguageRoute($router->getCurrentRouteName());
return $redirector->gotoRouteAndExit($params, $route, false);
iii
iii
iii
第一个问题是,你认为这种方式可以提供多兰支持。 我已注意到,所有这种链条都大大降低了服务器的运行速度,服务器的响应时间约为4秒钟。
Main question is: Currently I have to implement such feature: I have domain www.domain2.com that should work just with single module e.g. "foobar"... and it should be available via second url... or, of course, it should work like www.domain1.com/en/foobar by default...
在“诱杀装置一”类中提供这种功能
// Instantiate default module route
$routeDefault = new Zend_Controller_Router_Route_Module(
array(),
$front->getDispatcher(),
$front->getRequest()
);
$foobarHostname = new Zend_Controller_Router_Route_Hostname(
www.domain2.com ,
array(
module => foobar
)
);
$router->addRoute("foobarHostname", $foobarHostname->chain($routeDefault));
而且,这并不奏效,因为我发现,Default总会发现正确的“foobar”模式,其价值是“default”。
Then I ve implemented default router like this:
new Zend_Controller_Router_Route(
:controller/:action/* ,
array(
controller => index ,
action => index
);
);
但是,这仍然只是徒劳无益的工作,只是在我评论Foo_Plugin_Language BUT的“标准”方法时,才开始使用无语言的工作。 我需要语言支持,我曾以各种可能的守则组合而做了很多工作,最后,在缺席的情况下提供语言支持:
class Project_Controller_Router_Route extends Zend_Controller_Router_Route_Module
{ /** * @param string $path * @param bool $partial * @return array */ public function match($path, $partial = false) { $result = array();
$languageRegexp = %^/([a-z]{2iii)(/.*)%i ;
if (preg_match($languageRegexp, $path, $matches)) {
$result[ lang ] = $matches[1];
$path = $matches[2];
iii
$parentMatch = parent::match($path);
if (is_array($parentMatch)) {
$result = array_merge($result, $parentMatch);
iii
return $result;
iii
iii
因此,语言参数从道路上仔细抽取,正常处理按常规进行。
但是,当我下部法典时,我无法通过www.domain2.com url进入“ fbar”模块,因为申请中的模块名称总是“default”。
$front = Zend_Controller_Front::getInstance();
/** @var Zend_Controller_Router_Rewrite $router */
$router = $front->getRouter();
$dispatcher = $front->getDispatcher();
$request = $front->getRequest();
$routerDefault = new Project_Controller_Router_Route(array(), $dispatcher, $request);
$router->removeDefaultRoutes();
$router->addRoute( default , $routerDefault);
$foobarHostname = new Zend_Controller_Router_Route_Hostname(
www.domain2.com ,
array(
module => foobar
)
);
$router->addRoute("foobar", $foobarHostname->chain($routerDefault));
页: 1
- Problem is that I should implement feature that will provide access for the secondary domain to the specific module of ZendFramework, and I should save multi-language support. And I cannot find a way, how to manage all of this...
- Secondary question is about performance of chain router, it makes site work very-very slow...