日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[转]Laravel 4之URL生成

發(fā)布時(shí)間:2024/4/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转]Laravel 4之URL生成 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Laravel 4之URL生成 http://dingjiannan.com/2013/laravel-url/

獲取當(dāng)前URL

獲取當(dāng)前URL有兩種方式,URL::current()或URL::full(),區(qū)別是返不返回GET參數(shù)如

  • Route::get('/current/url',function()
  • {
  • return URL::current();
  • });
  • 輸入/current/url?foo=bar時(shí)只顯示http://myapp.dev/current/url。使用URL::full()則顯示http://myapp.dev/current/url?foo=bar

    獲取之前的URL

  • // app/routes.php
  • Route::get('first',function()
  • {
  • // Redirect to the second route.
  • returnRedirect::to('second');
  • });
  • Route::get('second',function()
  • {
  • eturn URL::previous();
  • });
  • 輸入/first,返回http://loacahost,URL::previous()返回的是之前到first的路由

    生成URL

    使用URL::to()生成URL,如

  • Route::get('example',function()
  • {
  • return URL::to('another/route', array('foo','bar'));
  • });
  • 生成的URL為http://myapp.dev/another/route/foo/bar,如需將HTTP協(xié)議變?yōu)镠TTPS,則用

  • URL::to('another/route', array('foo','bar'),true);
  • 或是使用

  • URL::secure('another/route', array('foo','bar'));
  • 使用路由別名生成URL

  • Route::get('the/best/avenger', array('as'=>'ironman',function()
  • {
  • return'Tony Stark';
  • }));
  • Route::get('example',function()
  • {
  • return URL::route('ironman');
  • });
  • 使用URL參數(shù)

  • 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'));
  • });
  • 到控制器的URL

  • // Route to the Stark controller.
  • Route::get('tony/the/{first}/genius','Stark@tony');
  • Route::get('example',function()
  • {
  • return URL::action('Stark@tony', array('narcissist'));
  • });
  • 到資源的絕對(duì)URL

  • Route::get('example',function()
  • {
  • return URL::asset('img/logo.png');
  • });
  • 返回http://myapp.dev/img/logo.png,同樣,使用HTTPS

  • return URL::asset('img/logo.png',true);
  • 或是

  • return URL::secureAsset('img/logo.png');
  • 在視圖中生成URL

    使用url()在視圖中生成URL,方法跟參數(shù)跟以上的沒什么區(qū)別,使用如下

  • <ahref="">My Route</a>
  • 或是

  • <ahref="">My Route</a>
  • 使用路由別名

  • <ahref="">My Route</a>
  • 使用控制器

  • <ahref="">My Route</a>
  • 使用資源

  • <ahref="">My Route</a>
  • <ahref="">My Route</a>
  • 結(jié)束

    點(diǎn)擊查看評(píng)論

    總結(jié)

    以上是生活随笔為你收集整理的[转]Laravel 4之URL生成的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。