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
- '<action:(login|logout|about)>' => 'site/<action>',
- // a custom rule to handle '/Manufacturer/Model'
- array(
- 'class' => 'application.components.CarUrlRule',
- 'connectionID' => 'db',
- ),
- // a standard rule to handle 'post/update' and so on
- '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
- ),
自定义url规则类拓展自 CBaseUrlRule ,可以像如下方式实现:
- class CarUrlRule extends CBaseUrlRule
- {
- public $connectionID = 'db';
- public function createUrl($manager,$route,$params,$ampersand)
- {
- if ($route==='car/index')
- {
- if (isset($params['manufacturer'], $params['model']))
- return $params['manufacturer'] . '/' . $params['model'];
- else if (isset($params['manufacturer']))
- return $params['manufacturer'];
- }
- return false; // this rule does not apply
- }
- public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
- {
- if (preg_match('%^(\w+)(/(\w+))?$%', $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['manufacturer'] and/or $_GET['model']
- // and return 'car/index'
- }
- return false; // this rule does not apply
- }
- }
下载地址:http://www.yiiframework.com/download/
立即学习“PHP免费学习笔记(深入)”;
原文出自:开源中国社区











