当前位置: 首页 > 工具软件 > yaf-lib > 使用案例 >

Yaf路由使用

沈开畅
2023-12-01

修改\application\Bootstrap.php文件的路由方法

	public function _initRoute(Yaf_Dispatcher $dispatcher) {
		//在这里注册自己的路由协议,默认使用简单路由
		//通过派遣器得到默认的路由器
		$router = Yaf_Dispatcher::getInstance()->getRouter();

		//index.php?/list/12
		//list方法中使用$this->getRequest()->getParam('catid')
		$routeRewrite = new Yaf_Route_Rewrite(
					"/list/:catid",
					array(
						'controller' => 'blog',
						'action' => 'list' //注意是action,网上不少写错名
					)
				);
		$router->addRoute('rewrite', $routeRewrite);

		//index.php?m=***&c=***&a=**
		$routeSimple = new Yaf_Route_Simple("m", "c", "a");
		$router->addRoute("simple", $routeSimple);

		//index.php?r=m/a/c
		$routeSupervar = new Yaf_Route_Supervar("r");
		$router->addRoute("supervar", $routeSupervar);
	}

 类似资料: