[转]Laravel 4之URL生成
生活随笔
收集整理的這篇文章主要介紹了
[转]Laravel 4之URL生成
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Laravel 4之URL生成 http://dingjiannan.com/2013/laravel-url/ Route::get('/current/url',function() { return URL::current(); }); // app/routes.php Route::get('first',function() { // Redirect to the second route. returnRedirect::to('second'); }); Route::get('second',function() { eturn URL::previous(); }); Route::get('example',function() { return URL::to('another/route', array('foo','bar')); }); URL::to('another/route', array('foo','bar'),true); URL::secure('another/route', array('foo','bar')); Route::get('the/best/avenger', array('as'=>'ironman',function() { return'Tony Stark'; })); Route::get('example',function() { return URL::route('ironman'); }); Route::get('the/{first}/avenger/{second}', array( 'as'=>'ironman', function($first, $second){ return"Tony Stark, the {$first} avenger {$second}."; } )); Route::get('example',function() { return URL::route('ironman', array('best','ever')); }); // Route to the Stark controller. Route::get('tony/the/{first}/genius','Stark@tony'); Route::get('example',function() { return URL::action('Stark@tony', array('narcissist')); }); Route::get('example',function() { return URL::asset('img/logo.png'); }); return URL::asset('img/logo.png',true); return URL::secureAsset('img/logo.png'); <ahref="">My Route</a> <ahref="">My Route</a> <ahref="">My Route</a> <ahref="">My Route</a> <ahref="">My Route</a> <ahref="">My Route</a>
獲取當(dāng)前URL
獲取當(dāng)前URL有兩種方式,URL::current()或URL::full(),區(qū)別是返不返回GET參數(shù)如
輸入/current/url?foo=bar時(shí)只顯示http://myapp.dev/current/url。使用URL::full()則顯示http://myapp.dev/current/url?foo=bar
獲取之前的URL
輸入/first,返回http://loacahost,URL::previous()返回的是之前到first的路由
生成URL
使用URL::to()生成URL,如
生成的URL為http://myapp.dev/another/route/foo/bar,如需將HTTP協(xié)議變?yōu)镠TTPS,則用
或是使用
使用路由別名生成URL
使用URL參數(shù)
到控制器的URL
到資源的絕對URL
返回http://myapp.dev/img/logo.png,同樣,使用HTTPS
或是
在視圖中生成URL
使用url()在視圖中生成URL,方法跟參數(shù)跟以上的沒什么區(qū)別,使用如下
或是
使用路由別名
使用控制器
使用資源
結(jié)束
點(diǎn)擊查看評(píng)論總結(jié)
以上是生活随笔為你收集整理的[转]Laravel 4之URL生成的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北京科技大学研究生考试 《工程热力学》(
- 下一篇: 给文本框添加模糊搜索功能(“我记录”MV