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/
原文出自:开源中国社区
