我在我的應用程序中重定向請求時遇到問題。如何將請求重定向到www.example.com/admin到Zend中的不同模塊
我的規則:
- employer.domain.com - 應指向用人單位的頁面 - 使用默認模塊
- employer.domain.com/panel/ - 應指向特定僱主的管理頁面 - 使用儀表板模塊
- www.domain.com - s HOULD點聚集所有僱主頁 - 使用默認模塊
我已經測試了很多不同的路線,但是當一個路由的工作,其他的會出現問題。通常它只適用於根路徑,但是當我添加對某個控制器和操作的調用時 - 它崩潰了。也許我應該寫定製控制器插件?你怎麼看?
這是我目前的配置。這是一團糟,但也許它會幫助捕捉一些愚蠢的錯誤。
// 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));
隨着你張貼的路線,他們哪個按預期工作,哪些沒有?你能舉一個例子,當你添加控制器和動作時不起作用的URL。 –
Works:employer.domain.com,employer.domain.com/panel/,domain.com 不工作:employer.domain.com/some-controller/some-action –