2016-09-02 11 views
0

私はfrontend/web/cssにあるCSSファイルをバックエンドのメインレイアウトに含めるようにしています。バックエンド用にを使用していますが、ですが、フロントエンドにエラーがあります。フロントエンドWeb URLはstaging.example.comで、バックエンドWeb URLはbackend.example.comです。Yend2のバックエンドにFrontend CSSファイルを含める

<?php 
namespace frontend\assets; 
use yii\web\AssetBundle; 

class IconAsset extends AssetBundle 
{ 
    public $sourcePath = '@frontend/web'; 
    public $css = [ 
     'css/icon.css', 
    ]; 
} 
?> 

コードフロントエンドのレイアウトmain.php内部

use frontend\assets\IconAsset; 
IconAsset::register($this); 

次のようにフロントエンドにカスタム・アセット・バンドルを作成する必要がありますコードバックエンドのレイアウトmain.php内部

use frontend\assets\IconAsset; 
IconAsset::register($this); 

答えて

0

続く:

 namespace frontend\assets; 
    use yii\web\AssetBundle; 
    use yii\web\YiiAsset; 

     class CustomAsset extends AssetBundle{ 
      public $basePath = '@webroot'; 
      public $baseUrl = '@web'; 
      public $css = [ 
       'css/custom.css', 
       'css/another_css.css' 
      ]; 
     }` 

フロントエンドのWebアクセスフォルダ内のコードの上に置き、あなたのコメントのための

use frontend\assets\CustomAsset; 
use Yii; 

$bundle = CustomAsset::register(Yii::$app->view); 
+0

感謝を次のようにbakendメインのレイアウトファイルには、この資産を登録します。私のコードはバックエンドで働いていますが、フロントエンドのメインレイアウトにIconAssetを登録しようとするとエラーが発生します。フロントエンドのメインレイアウトでこれを使用する方法を教えてください。 – Alex

+0

この回答を参照してください[カルロスマンゾー](http://stackoverflow.com/questions/37154991/share-assets-between-frontend-and-backend-in-yii2-advanced-template) –

+0

私はあなたのコードを試みたが、持っている私の前にいる(staging.example.com)とバックエンド(backend.example.com)のサブドメインが異なるため、クロスオリジン要求エラー – Alex

関連する問題