yii\web\View::registerCssFile PHP Method

registerCssFile() public method

Registers a CSS file.
public registerCssFile ( string $url, array $options = [], string $key = null )
$url string the CSS file to be registered.
$options array the HTML attributes for the link tag. Please refer to [[Html::cssFile()]] for the supported options. The following options are specially handled and are not treated as HTML attributes: - `depends`: array, specifies the names of the asset bundles that this CSS file depends on.
$key string the key that identifies the CSS script file. If null, it will use $url as the key. If two CSS files are registered with the same key, the latter will overwrite the former.
    public function registerCssFile($url, $options = [], $key = null)
    {
        $url = Yii::getAlias($url);
        $key = $key ?: $url;
        $depends = ArrayHelper::remove($options, 'depends', []);
        if (empty($depends)) {
            $this->cssFiles[$key] = Html::cssFile($url, $options);
        } else {
            $this->getAssetManager()->bundles[$key] = Yii::createObject(['class' => AssetBundle::className(), 'baseUrl' => '', 'css' => [strncmp($url, '//', 2) === 0 ? $url : ltrim($url, '/')], 'cssOptions' => $options, 'depends' => (array) $depends]);
            $this->registerAssetBundle($key);
        }
    }

Usage Example

 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     $manager = $view->getAssetManager();
     foreach ($this->css as $css) {
         $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
     }
     $view->registerJsFile($this->basketJs);
     $jsFiles = [];
     foreach ($this->js as $js) {
         $jsFiles[] = Json::encode(['url' => $manager->getAssetUrl($this, $js)]);
     }
     $view->registerJs(sprintf('basket.require(%s);', implode(",\r\n", $jsFiles)), View::POS_END);
 }
All Usage Examples Of yii\web\View::registerCssFile