php – 缩短Zend框架路由定义
发布时间:2020-12-13 13:39:44 所属栏目:PHP教程 来源:网络整理
导读:如何缩短Zend Framework中自定义路由的定义?我目前有这个定义: $route = new Zend_Controller_Router_Route( ":module/:id",array( "controller" = "index","action" = "index" ),array("id" = "d+"));self::$frontController-getRouter()-addRoute('shor
如何缩短Zend Framework中自定义路由的定义?我目前有这个定义:
$route = new Zend_Controller_Router_Route( ":module/:id",array( "controller" => "index","action" => "index" ),array("id" => "d+") ); self::$frontController->getRouter()->addRoute('shortcutOne',$route); $route = new Zend_Controller_Router_Route( ":module/:controller/:id",array("action" => "index"),array("id" => "d+") ); self::$frontController->getRouter()->addRoute('shortcutTwo',$route); $route = new Zend_Controller_Router_Route( ":module/:controller/:action/:id",null,array("id" => "d+") ); self::$frontController->getRouter()->addRoute('shortcutThree',$route); 有没有办法更好地结合这些规则?
当设置这样的路由时,我使用配置文件.作为首选,我使用XML存储我的配置数据,但是这些可以轻松地以另一种支持的格式存储.然后,我将路由从配置添加到我的引导中的路由器.
配置: <config> <routes> <shortcutone type="Zend_Controller_Router_Route"> <route>:module/:id</route> <defaults> <controller>index</controller> <action>index</action> </defaults> <reqs id="d+"> </shortcutone> <shortcuttwo type="Zend_Controller_Router_Route"> <route>:module/:controller/:id</route> <defaults> <controller>index</controller> </defaults> <reqs id="d+"> </shortcuttwo> <shortcutthree type="Zend_Controller_Router_Route"> <route>:module/:controller/:action/:id</route> <defaults> <controller>index</controller> <action>index</action> </defaults> <reqs id="d+"> </shortcutthree> </routes> </config> 引导 $config = new Zend_Config_Xml('config.xml'); $router = Zend_Controller_Front::getInstance()->getRouter(); $router->addConfig($config,'routes'); 显然,还有其他的选择,我鼓励你阅读这个documentation,但是,这适合你的例子. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |