使用路由別名生成URL

  1. Route::get('the/best/avenger', array('as'=>'ironman',function()
  2. {
  3. return'Tony Stark';
  4. }));
  5. Route::get('example',function()
  6. {
  7. return URL::route('ironman');
  8. });

使用URL參數

  1. Route::get('the/{first}/avenger/{second}', array(
  2. 'as'=>'ironman',
  3. function($first, $second){
  4. return"Tony Stark, the {$first} avenger {$second}.";
  5. }
  6. ));
  7. Route::get('example',function()
  8. {
  9. return URL::route('ironman', array('best','ever'));
  10. });

到控制器的URL

  1. // Route to the Stark controller.
  2. Route::get('tony/the/{first}/genius','Stark@tony');
  3. Route::get('example',function()
  4. {
  5. return URL::action('Stark@tony', array('narcissist'));
  6. });

到資源的絕對URL

  1. Route::get('example',function()
  2. {
  3. return URL::asset('img/logo.png');
  4. });

返回http://myapp.dev/img/logo.png,同樣,使用HTTPS

  1. return URL::asset('img/logo.png',true);

或是

  1. return URL::secureAsset('img/logo.png');

在視圖中生成URL

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

  1. <ahref="">My Route</a>

或是

  1. <ahref="">My Route</a>

使用路由別名

  1. <ahref="">My Route</a>

使用控制器

  1. <ahref="">My Route</a>

使用資源

  1. <ahref="">My Route</a>
  2. <ahref="">My Route</a>

結束

關於url可以看官網的api

轉自:http://www.cnblogs.com/steven9801/p/3560738.html

更多:http://codego.net/573717/