0

如何在 Laravel4.2 中配置 url 或 base url 以保护协议 https 而无需在 html builder 中设置手册。

{{ 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')) }}
4

1 回答 1

0

目前尚不清楚您需要什么。如果您的页面 URL 在 https 方案中,则该页面上的每个资产 URL 都将在 https 中自动生成,但是如果您只需要在 http 请求的页面上通过 https 链接某些类型的资产,则必须实现自己的自HtmlBuilder定义覆盖需要强制生成 https URL 的辅助方法

<?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配置中,您应该将 default 替换HtmlServiceProvider为您的 custom MyAppHtmlServiceProvider

<?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']);
        });
    }
}
于 2016-10-25T06:58:43.853 回答