AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
接下来,我们来尝试一些复杂的路由规则定义满足不同的路由变量。在此之前,首先增加一个控制器类如 下: <?php namespace app\\index\\controller; class Blog { public function get($id) { return '查看id=' . $id . '的内容'; } public function read($name) { return '查看name=' . $name . '的内容'; } public function archive($year, $month) { return '查看' . $year . '/' . $month . '的归档内容'; } } 添加如下路由规则: return \[ 'blog/:year/:month' => \['blog/archive', \['method' => 'get'\], \['year' => '\\d{4}', 'm onth' => '\\d{2}'\]\], 'blog/:id' => \['blog/get', \['method' => 'get'\], \['id' =>'\\d+'\]\], 'blog/:name' => \['blog/read', \['method' => 'get'\], \['name' =>'\\w+'\]\], \]; 在上面的路由规则中,我们对变量进行的规则约束,变量规则使用正则表达式进行定义。 我们看下几种URL访问的情况 //访问id为5的内容 <http://tp5.com/blog/5> //访问name为thinkphp的内容 <http://tp5.com/blog/thinkphp> //访问2015年5月的归档内容 <http://tp5.com/blog/2015/05>