Using AssetManager wrong?

I don’t think I’m doing this right…

All my controllers inherit this method:




    public function getAssetsUrl() {

        if ($this->_assetsUrl === null)

            $this->_assetsUrl = Yii::app()->getAssetManager()->publish(

                    Yii::getPathOfAlias('application.components.assets'));

        return $this->_assetsUrl;

    }



And in my main layout file, at the top, I have this:


<?php

yii::app()->clientScript->registerCoreScript('jquery', CClientScript::POS_END);

yii::app()->clientScript->registerScriptFile($this->assetsUrl."/js/highstock/highstock.js", CClientScript::POS_END);

yii::app()->clientScript->registerScriptFile($this->assetsUrl."/js/site/charts.js", CClientScript::POS_END);

yii::app()->clientScript->registerScriptFile($this->assetsUrl."/js/site/main.js", CClientScript::POS_END);

yii::app()->clientScript->registerCssFile($this->assetsUrl."/css/form.css");

yii::app()->clientScript->registerCssFile($this->assetsUrl."/css/Cashview.css");

yii::app()->clientScript->registerCssFile($this->assetsUrl."/css/Primary-menu_style.css");

yii::app()->clientScript->registerCssFile($this->assetsUrl."/css/Sub-menu_style.css");

yii::app()->clientScript->registerCssFile($this->assetsUrl."/css/fonts/stylesheet.css");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "httx://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="httx://www.w3.org/1999/xhtml" >


....

Am I doing this right?

I don’t feel like I am.

If you want a css/js file to be included on every page of your site, simply put them in a web-accessible directory and use <script> and <link> elements as you would normally do without Yii.

Use clientScript component when a css/js file is only required by one or a few page.

Use assetManager when a reusable component (typically a widget or a module) requires its own css/js files to be loaded.