作者:我的爱来了2012_800 | 来源:互联网 | 2018-05-08 01:56
PHP开发框架Yii1.1.8发布。该版本引入了超过80个新功能、加强和bug修复。你可以编写自定义URL规则类来为应用程序处理任意复杂的URL格式,改进的classautoloader等。Yii是一个高性能的PHP5的web应用程序开发框架。通过一个简单的命令行工具yiic可以快速
PHP开发框架Yii 1.1.8 发布。该版本引入了超过80个新功能、加强和bug修复。你可以编写自定义URL规则类来为应用程序处理任意复杂的URL格式,改进的class autoloader等。 Yii是一个高性能的PHP5的web应用程序开发框架。通过一个简单的命令行工具 yiic 可以快速
PHP开发框架Yii 1.1.8 发布。该版本引入了超过80个新功能、加强和bug修复。你可以编写自定义URL规则类来为应用程序处理任意复杂的URL格式,改进的class autoloader等。
Yii是一个高性能的PHP5的web应用程序开发框架。通过一个简单的命令行工具 yiic 可以快速创建一个web应用程序的代码框架,开发者可以在生成的代码框架基础上添加业务逻辑,以快速完成应用程序的开发。
使用自定义url规则类的URL 规则配置:
- array(
- // a standard rule mapping '/login' to 'site/login', and so on
- &#039;<action:(login|logout|about)>&#039; => &#039;site/<action>&#039;,
-
- // a custom rule to handle &#039;/Manufacturer/Model&#039;
- array(
- &#039;class&#039; => &#039;application.components.CarUrlRule&#039;,
- &#039;connectionID&#039; => &#039;db&#039;,
- ),
-
- // a standard rule to handle &#039;post/update&#039; and so on
- &#039;<controller:\w+>/<action:\w+>&#039; => &#039;<controller>/<action>&#039;,
- ),
-
自定义url规则类拓展自 CBaseUrlRule
,可以像如下方式实现:
- class CarUrlRule extends CBaseUrlRule
- {
- public $connectionID = &#039;db&#039;;
-
- public function createUrl($manager,$route,$params,$ampersand)
- {
- if ($route===&#039;car/index&#039;)
- {
- if (isset($params[&#039;manufacturer&#039;], $params[&#039;model&#039;]))
- return $params[&#039;manufacturer&#039;] . &#039;/&#039; . $params[&#039;model&#039;];
- else if (isset($params[&#039;manufacturer&#039;]))
- return $params[&#039;manufacturer&#039;];
- }
- return false; // this rule does not apply
- }
-
- public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
- {
- if (preg_match(&#039;%^(\w+)(/(\w+))?$%&#039;, $pathInfo, $matches))
- {
- // check $matches[1] and $matches[3] to see
- // if they match a manufacturer and a model in the database
- // If so, set $_GET[&#039;manufacturer&#039;] and/or $_GET[&#039;model&#039;]
- // and return &#039;car/index&#039;
- }
- return false; // this rule does not apply
- }
- }
-
下载地址:http://www.yiiframework.com/download/
原文出自:开源中国社区