Yii2 how to include multiple css files from specific view or controller action


Tags: javascript,css,frameworks,yii2-advanced-app,yii2-user

Problem :

I have installed YII2 of my local server and I want to include separate css file from specific view or controller action, I have used a method but the method on include one css file in my specific view , could any one answer me for the solution my code is below. The firs file is include and the remaining is ignored.

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/iCheck/flat/blue.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], 'css-screen-theme');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/morris/morris.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], 'css-screen-theme');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/jvectormap/jquery-jvectormap-1.2.2.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], 'css-screen-theme');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/datepicker/datepicker3.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], 'css-screen-theme');



Solution :

Just remove one parameter from the above code , the remaining code is correct.I am sending an example for modified code.

this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/iCheck/flat/blue.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], '');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/morris/morris.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], '');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/jvectormap/jquery-jvectormap-1.2.2.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], '');

$this->registerCssFile(Yii::$app->request->BaseUrl."/assets/plugins/datepicker/datepicker3.css", [ 'depends' => [BootstrapAsset::className()], 'media' => 'screen', ], ''); Now all the css files will be shown now.


    CSS Howto..

    How to handle mouseover properly on a flipped div?

    how to create css background effect in extjs4.0 application(on selection)

    How can I use a CSS selector to match two classes being present?

    Show or hide div based on selected value

    How to center text based on only one of two merged cells ? html/css

    How to disable Javascript/CSS minification in ASP.NET MVC 4 Beta

    Using CSS, how do I change the font color of parent
  • tag if child
  • tag is hovered over
  • How to make a font gisha-regular?

    How to identify device to make separate css for iPad and Galaxy Tab?

    How to remove right border

    How to repeat nth-child rules for an infinite sequence in CSS

    How to reset input element style

    How can I make a DIV cursor and background color change if I hover over it?

    jquery .show() from only the selected div

    How can I center a table relative to one column in HTML/CSS?

    How to overlap auto-scaling images with an auto-scaling background

    How to apply diffrent css style on different events of an asp button?

    how to override min-width

    How can i use “z-index” as an css attribute selector?

    How To Make Entire 'li' Area and Text A Clickable Link

    how to make sure image shows over my twitter bootstrap 3 input field

    How to apply CSS after adding elemnts with jquery

    How to set the styles on “*” and pseudo states with JavaScript? [closed]

    How to apply @media for css attribute that are set via jquery

    How to make a CSS border for a dropdown menu?

    How to Add CSS Reference to .NET SyndicationFeed?

    How to display .toggle or .Animate to all connected browser sessions using Meteor

    How to force a list to be vertical using html css

    How to apply multiple transforms in CSS?

    How to eliminate the overlap border using CSS only