使用路由别名生成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/