2016-10-25 18 views
0

如何在Laravel4.2中配置url或base url以在html builder中保护协议https而不设置手动。如何在laravel4.2中为安全协议(https)配置html构建器

{{ HTML::style('front_assets/plugins/bootstrap/css/bootstrap.min.css') }} 
     {{ HTML::style('front_assets/css/style.css')}} 
     <!-- CSS Implementing Plugins --> 

     {{ HTML::style('front_assets/plugins/font-awesome/css/font-awesome.min.css') }} 
     {{ HTML::style('front_assets/plugins/sky-forms/version-2.0.1/css/custom-sky-forms.css') }} 

     {{ HTML::style('front_assets/plugins/scrollbar/src/perfect-scrollbar.css') }} 
     {{ HTML::style('front_assets/plugins/fullcalendar/fullcalendar.css') }} 
     {{ HTML::style('front_assets/plugins/fullcalendar/fullcalendar.print.css',array('media' => 'print')) }} 

回答

0

目前尚不清楚您需要什么。如果您的网页网址位于https方案中,那么该网页上的每个资产网址都将自动生成https网址,但如果您只需要通过http请求的网页上的https链接某些类型的资产,则必须实现您自己的自定义HtmlBuilder重写你需要被迫产生https网址

<?php namespace MyApp\Html; 

use Illuminate\Html\HtmlBuilder; 

class MyAppHtmlBuilder extends HtmlBuilder { 

    public function style($url, $attributes = array(), $secure = true) 
    {               ^^^^ 
     return parent::style($url, $attributes, $secure) 
    } 
} 

然后在app.php配置,你应该用你的自定义MyAppHtmlServiceProvider替换默认HtmlServiceProvider辅助方法。

<?php namespace MyApp\Html; 

use Illuminate\Html\HtmlServiceProvider; 
use MyApp\Html\MyAppHtmlBuilder; 

class MyAppHtmlServiceProvider extends HtmlServiceProvider { 

    protected function registerHtmlBuilder() 
    { 
     $this->app->bindShared('html', function($app) 
     { 
      return new MyAppHtmlBuilder($app['url']); 
     }); 
    } 
}