Yii Framework Forum: Using AssetManager wrong? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using AssetManager wrong? Rate Topic: -----

#1 User is offline   fishgills 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 28-September 11

Posted 29 November 2011 - 01:32 PM

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.
0

#2 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 445
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 29 November 2011 - 05:23 PM

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.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users