laravel技术交流群 :784030154
1.默认访问index/index/index
2.url访问时,其中控制器和操作名不区分大小写,针对控制器使用大驼峰命名方式,例如HelloWorld,则默认正确的访问url为index/hello_world/index,如将配置文件中的'url_convert'=>false,关闭url自动转换,则可使用index/HelloWorld/index方式访问。
3.参数传入:当控制器中的操作采用绑定参数转入,将自动获取url中的同名参数作为方法的参数,不受顺序的影响。
如将配置文件中的url_param_type=1,将严格按照转入的参数顺序获取。
ps:按照顺序绑定参数的话,操作方法的参数只能获取url pathinfo变量,将不接受get和post传值
4.隐藏index.php入口文件:
Apache:在入口文件的同级目录添加.htaccess文件
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
Nginx :在Nginx.conf添加
location / { // …..省略部分代码
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
5.隐藏url中模块名,则可在application/route.php配置路由
return [
'hello/[:name]' => 'index/hello', // 通过http://localhost/hello访问index/hello
'hello/[:name]' => 'index/hello', // 路由参数name为可选
'hello/[:name]$' => 'index/hello', // 必须以hello开头访问
'hello/[:name]'=>['index/hello',['metod'=>'get','ext'=>'html']],//路由限制必须以get方式,.html后缀方式访问
'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+']],
'__pattern__' => [
'name' => '\w+',
'id' => '\d+',
'year' => '\d{4}',
'month' => '\d{2}',
],//定义路由中的参数格式
];
设置url中的分隔符:application/config.php配置‘pathinfo_depr’=>'_'
ps:1.注意路由配置不支持在模块配置文件中设置。
2.一旦设置了路由,就不能采用原有的pathinfo的index/hello/index访问
6.生成url地址
Url::build('blog/read','name=thinkphp');
Url::build('blog/read',['name'=>'thinkphp']);