diff --git a/CHANGELOG b/CHANGELOG index c0e86c178..8fadb110a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ Version 1.0 to be released - Added COutputCache::varyByRoute (Qiang) - Added 'params' to HTML options that are used in CHtml methods (Qiang) - Added CDbConnection::emulatePrepare (Qiang) +- Added CWebApplication::clientScript and removed CController::clientScript (Qiang) - Refactored UserIdentity generated by yiic webapp (Qiang) - Refactored CLinkPager (Qiang) - Refactored CFilter (Qiang) diff --git a/UPGRADE b/UPGRADE index 0e31100a7..d4069b38b 100644 --- a/UPGRADE +++ b/UPGRADE @@ -12,6 +12,7 @@ for both A and B. Upgrading from v1.0rc --------------------- - CLinkPager is changed significantly in appearance and the generated HTML code. +- CController::clientScript is removed. Please use Yii::app()->clientScript instead. Upgrading from v1.0b diff --git a/docs/guide/basics.application.txt b/docs/guide/basics.application.txt index ce39b439f..94814d966 100644 --- a/docs/guide/basics.application.txt +++ b/docs/guide/basics.application.txt @@ -167,6 +167,15 @@ session-related functionalities. - [assetManager|CWebApplication::assetManager]: [CAssetManager] - manages the publishing of private asset files. + - [user|CWebApplication::user]: [CWebUser] - represents the user session information. + + - [themeManager|CWebApplication::themeManager]: [CThemeManager] - manages themes. + + - [authManager|CWebApplication::authManager]: [CAuthManager] - manages role-based access control (RBAC). + + - [clientScript|CWebApplication::clientScript]: [CClientScript] - +manages client scripts (javascripts and CSS). + Besides the above compoennts, a component named [cache|CApplication::cache] is also declared but without specifying its class. The [cache|CApplication::cache] component is used by Yii for data diff --git a/framework/web/CClientScript.php b/framework/web/CClientScript.php index 4ec9c2741..061f037eb 100644 --- a/framework/web/CClientScript.php +++ b/framework/web/CClientScript.php @@ -16,14 +16,13 @@ * @package system.web * @since 1.0 */ -class CClientScript extends CComponent +class CClientScript extends CApplicationComponent { /** * @var boolean whether JavaScript should be enabled. Defaults to true. */ public $enableJavaScript=true; - private $_controller; private $_packages; private $_dependencies; private $_baseUrl; @@ -36,15 +35,6 @@ class CClientScript extends CComponent private $_bodyScripts=array(); - /** - * Constructor. - * @param CController controller - */ - public function __construct($controller) - { - $this->_controller=$controller; - } - /** * Cleans all registered scripts. */ @@ -58,7 +48,7 @@ class CClientScript extends CComponent $this->_bodyScriptFiles=array(); $this->_bodyScripts=array(); - $this->_controller->recordCachingAction('clientScript','reset',array()); + Yii::app()->getController()->recordCachingAction('clientScript','reset',array()); } /** @@ -127,6 +117,17 @@ class CClientScript extends CComponent return $this->_baseUrl=Yii::app()->getAssetManager()->publish(YII_PATH.'/web/js/source'); } + /** + * Sets the base URL of all core javascript files. + * This setter is provided in case when core javascript files are manually published + * to a pre-specified location. This may save asset publishing time for large-scale applications. + * @param string the base URL of all core javascript files. + */ + public function setCoreScriptUrl($value) + { + $this->_baseUrl=$value; + } + /** * Renders the specified core javascript library. * Any dependent libraries will also be rendered. @@ -177,7 +178,7 @@ class CClientScript extends CComponent { $this->_coreScripts[$name]=$name; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerCoreScript',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerCoreScript',$params); } } @@ -191,7 +192,7 @@ class CClientScript extends CComponent { $this->_cssFiles[$url]=$media; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerCssFile',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerCssFile',$params); } /** @@ -205,7 +206,7 @@ class CClientScript extends CComponent $this->_css[$id]=array($css,$media); $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerCss',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerCss',$params); } /** @@ -218,7 +219,7 @@ class CClientScript extends CComponent { $this->_scriptFiles[$url]=$url; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerScriptFile',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerScriptFile',$params); } } @@ -231,7 +232,7 @@ class CClientScript extends CComponent { $this->_scripts[$id]=$script; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerScript',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerScript',$params); } /** @@ -244,7 +245,7 @@ class CClientScript extends CComponent { $this->_bodyScriptFiles[$url]=$url; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerBodyScriptFile',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScriptFile',$params); } } @@ -257,7 +258,7 @@ class CClientScript extends CComponent { $this->_bodyScripts[$id]=$script; $params=func_get_args(); - $this->_controller->recordCachingAction('clientScript','registerBodyScript',$params); + Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScript',$params); } /** diff --git a/framework/web/CController.php b/framework/web/CController.php index 8938153c5..b9ef1f311 100644 --- a/framework/web/CController.php +++ b/framework/web/CController.php @@ -83,7 +83,6 @@ class CController extends CBaseController private $_id; private $_action; private $_pageTitle; - private $_clientScript; private $_cachingStack; private $_clips; private $_dynamicOutput; @@ -227,11 +226,7 @@ class CController extends CBaseController */ public function processOutput($output) { - if($this->_clientScript) - { - $output=$this->_clientScript->render($output); - $this->_clientScript=null; - } + $output=Yii::app()->getClientScript()->render($output); if($this->_dynamicOutput) { @@ -539,14 +534,13 @@ class CController extends CBaseController } /** + * Returns the client script manager. + * This is a shortcut to {@link CWebApplication::getClientScript}. * @return CClientScript the client script manager */ public function getClientScript() { - if($this->_clientScript) - return $this->_clientScript; - else - return $this->_clientScript=new CClientScript($this); + return Yii::app()->getClientScript(); } /** diff --git a/framework/web/CWebApplication.php b/framework/web/CWebApplication.php index 8d4620a90..087674eb5 100644 --- a/framework/web/CWebApplication.php +++ b/framework/web/CWebApplication.php @@ -8,6 +8,19 @@ * @license http://www.yiiframework.com/license/ */ + 'user'=>array( + 'class'=>'CWebUser', + ), + 'themeManager'=>array( + 'class'=>'CThemeManager', + ), + 'authManager'=>array( + 'class'=>'CPhpAuthManager', + ), + 'clientScript'=>array( + 'class'=>'CClientScript', + ), + /** * CWebApplication extends CApplication by providing functionalities specific to Web requests. @@ -15,10 +28,14 @@ * CWebApplication manages the controllers in MVC pattern, and provides the following additional * core application components: *