Awa*_*wan 2 php url zend-framework
例如,我使用以下URL用于用户个人资料/仪表板:
example.com/person/person/profile
example.com/person/person/dashboard
Run Code Online (Sandbox Code Playgroud)
当人是模块,第二人是控制器和配置文件和仪表盘是行动.
但我希望如果用户转到以下网址,那么他们应该指出上面分别提到的相同网址:
example.com/person/profile
example.com/person/dashboard
Run Code Online (Sandbox Code Playgroud)
有没有办法总是从URL中删除模块名称?记住我想保留当前的目录结构.
谢谢
您可以使用路由执行此操作,在引导程序中添加此项
protected function _initRoutes()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
$router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config, 'routes');
Zend_Controller_Front::getInstance()->setRouter($router);
}
Run Code Online (Sandbox Code Playgroud)
然后在你的配置控制器中创建一个名为的文件routes.ini,这将包含你的自定义路由,试试这些
routes.person_profile.route = "person/profile"
routes.person_profile.defaults.controller = person
routes.person_profile.defaults.action = profile
routes.person_profile.defaults.module = person
routes.person_dashboard.route = "person/dashboard"
routes.person_dashboard.defaults.controller = person
routes.person_dashboard.defaults.action = dashboard
routes.person_dashboard.defaults.module = person
Run Code Online (Sandbox Code Playgroud)
这里我们定义了两条路线,remeber给每个独特的名字我称这些person_profile和person_dashboard.
的route值是将由被重写的URI controller,action和module值,例如路线person/profile将被自动分发到person控制器,所述person模块和profle动作.
希望有所帮助.