Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • ActionFormModelBase
  • CActiveDataProvider
  • CalendarEventFormModel
  • CallFormModel
  • CArrayDataProvider
  • CAssetManager
  • CBaseController
  • CBaseUrlRule
  • CCacheHttpSession
  • CClientScript
  • CController
  • CCookieCollection
  • CDataProvider
  • CDataProviderIterator
  • CDbHttpSession
  • CExtController
  • CFormModel
  • CHttpCookie
  • CHttpRequest
  • CHttpSession
  • CHttpSessionIterator
  • COutputEvent
  • CPagination
  • CreatePageFormModel
  • CSort
  • CSqlDataProvider
  • CTheme
  • CThemeManager
  • CUploadedFile
  • CUrlManager
  • CUrlRule
  • CWebApplication
  • CWebModule
  • CWidgetFactory
  • EditMobileFormsFormModel
  • EventCommentPublisherFormModel
  • EventFormModel
  • EventPublisherFormModel
  • FileSystemObjectDataProvider
  • MassActionFormModel
  • MobilePagination
  • NoteFormModel
  • NotificationsController
  • TimeFormModel
  • UploadLogoFormModel
  • X2FormModel
  • X2HttpRequest

Interfaces

  • IDataProvider
  • IWidgetFactory
  • Overview
  • Package
  • Class
  • Tree

Class CClientScript

CClientScript manages JavaScript and CSS stylesheets for views.

CComponent
Extended by CApplicationComponent implements IApplicationComponent
Extended by CClientScript
Package: system\web
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CClientScript.php
Methods summary
public
# reset( )

Cleans all registered scripts.

Cleans all registered scripts.

public
# render( string & $output )

Renders the registered scripts. This method is called in CController::render() when it finishes rendering content. CClientScript thus gets a chance to insert script tags at head and body sections in the HTML output.

Renders the registered scripts. This method is called in CController::render() when it finishes rendering content. CClientScript thus gets a chance to insert script tags at head and body sections in the HTML output.

Parameters

$output
string
$output the existing output that needs to be inserted with script tags
protected
# unifyScripts( )

Removes duplicated scripts from CClientScript::$scriptFiles.

Removes duplicated scripts from CClientScript::$scriptFiles.

Since

1.1.5
protected
# remapScripts( )

Uses CClientScript::$scriptMap to re-map the registered scripts.

Uses CClientScript::$scriptMap to re-map the registered scripts.

protected string
# renderScriptBatch( array $scripts )

Composes script HTML block from the given script values, attempting to group scripts at single 'script' tag if possible.

Composes script HTML block from the given script values, attempting to group scripts at single 'script' tag if possible.

Parameters

$scripts
array
$scripts script values to process.

Returns

string
HTML output
public
# renderCoreScripts( )

Renders the specified core javascript library.

Renders the specified core javascript library.

public
# renderHead( string & $output )

Inserts the scripts in the head section.

Inserts the scripts in the head section.

Parameters

$output
string
$output the output to be inserted with scripts.
public
# renderBodyBegin( string & $output )

Inserts the scripts at the beginning of the body section.

Inserts the scripts at the beginning of the body section.

Parameters

$output
string
$output the output to be inserted with scripts.
public
# renderBodyEnd( string & $output )

Inserts the scripts at the end of the body section.

Inserts the scripts at the end of the body section.

Parameters

$output
string
$output the output to be inserted with scripts.
public string
# getCoreScriptUrl( )

Returns the base URL of all core javascript files. If the base URL is not explicitly set, this method will publish the whole directory 'framework/web/js/source' and return the corresponding URL.

Returns the base URL of all core javascript files. If the base URL is not explicitly set, this method will publish the whole directory 'framework/web/js/source' and return the corresponding URL.

Returns

string
the base URL of all core javascript files
public
# setCoreScriptUrl( string $value )

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.

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.

Parameters

$value
string
$value the base URL of all core javascript files.
public string
# getPackageBaseUrl( string $name )

Returns the base URL for a registered package with the specified name. If needed, this method may publish the assets of the package and returns the published base URL.

Returns the base URL for a registered package with the specified name. If needed, this method may publish the assets of the package and returns the published base URL.

Parameters

$name
string
$name the package name

Returns

string
the base URL for the named package. False is returned if the package is not registered yet.

Since

1.1.8

See

CClientScript::registerPackage()
public static
# registerPackage( string $name )

Registers a script package that is listed in CClientScript::$packages. This method is the same as CClientScript::registerCoreScript().

Registers a script package that is listed in CClientScript::$packages. This method is the same as CClientScript::registerCoreScript().

Parameters

$name
string
$name the name of the script package.

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).

Since

1.1.7

See

renderCoreScript
public static
# registerCoreScript( string $name )

Registers a script package that is listed in CClientScript::$packages.

Registers a script package that is listed in CClientScript::$packages.

Parameters

$name
string
$name the name of the script package.

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).

See

renderCoreScript
public static
# registerCssFile( string $url, string $media = '' )

Registers a CSS file

Registers a CSS file

Parameters

$url
string
$url URL of the CSS file
$media
string
$media media that the CSS file should be applied to. If empty, it means all media types.

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public static
# registerCss( string $id, string $css, string $media = '' )

Registers a piece of CSS code.

Registers a piece of CSS code.

Parameters

$id
string
$id ID that uniquely identifies this piece of CSS code
$css
string
$css the CSS code
$media
string
$media media that the CSS code should be applied to. If empty, it means all media types.

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public static
# registerScriptFile( string $url, integer $position = null, array $htmlOptions = array() )

Registers a javascript file.

Registers a javascript file.

Parameters

$url
string
$url URL of the javascript file
$position
integer
$position the position of the JavaScript code. Valid values include the following:
  • CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • CClientScript::POS_END : the script is inserted at the end of the body section.
$htmlOptions
array
$htmlOptions additional HTML attributes

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public static
# registerScript( string $id, string $script, integer $position = null, array $htmlOptions = array() )

Registers a piece of javascript code.

Registers a piece of javascript code.

Parameters

$id
string
$id ID that uniquely identifies this piece of JavaScript code
$script
string
$script the javascript code
$position
integer
$position the position of the JavaScript code. Valid values include the following:
  • CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • CClientScript::POS_LOAD : the script is inserted in the window.onload() function.
  • CClientScript::POS_READY : the script is inserted in the jQuery's ready function.
$htmlOptions
array
$htmlOptions additional HTML attributes Note: HTML attributes are not allowed for script positions "CClientScript::POS_LOAD" and "CClientScript::POS_READY".

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public static
# registerMetaTag( string $content, string $name = null, string $httpEquiv = null, array $options = array(), string $id = null )

Registers a meta tag that will be inserted in the head section (right before the title element) of the resulting page.

Registers a meta tag that will be inserted in the head section (right before the title element) of the resulting page.

Note: Each call of this method will cause a rendering of new meta tag, even if their attributes are equal.

Example:

   $cs->registerMetaTag('example', 'description', null, array('lang' => 'en'));
   $cs->registerMetaTag('beispiel', 'description', null, array('lang' => 'de'));

Parameters

$content
string
$content content attribute of the meta tag
$name
string
$name name attribute of the meta tag. If null, the attribute will not be generated
$httpEquiv
string
$httpEquiv http-equiv attribute of the meta tag. If null, the attribute will not be generated
$options
array
$options other options in name-value pairs (e.g. 'scheme', 'lang')
$id
string
$id Optional id of the meta tag to avoid duplicates

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public static
# registerLinkTag( string $relation = null, string $type = null, string $href = null, string $media = null, array $options = array() )

Registers a link tag that will be inserted in the head section (right before the title element) of the resulting page.

Registers a link tag that will be inserted in the head section (right before the title element) of the resulting page.

Parameters

$relation
string
$relation rel attribute of the link tag. If null, the attribute will not be generated.
$type
string
$type type attribute of the link tag. If null, the attribute will not be generated.
$href
string
$href href attribute of the link tag. If null, the attribute will not be generated.
$media
string
$media media attribute of the link tag. If null, the attribute will not be generated.
$options
array
$options other options in name-value pairs

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.5).
public boolean
# isCssFileRegistered( string $url )

Checks whether the CSS file has been registered.

Checks whether the CSS file has been registered.

Parameters

$url
string
$url URL of the CSS file

Returns

boolean
whether the CSS file is already registered
public boolean
# isCssRegistered( string $id )

Checks whether the CSS code has been registered.

Checks whether the CSS code has been registered.

Parameters

$id
string
$id ID that uniquely identifies the CSS code

Returns

boolean
whether the CSS code is already registered
public boolean
# isScriptFileRegistered( string $url, integer $position = CClientScript::POS_HEAD )

Checks whether the JavaScript file has been registered.

Checks whether the JavaScript file has been registered.

Parameters

$url
string
$url URL of the javascript file
$position
integer
$position the position of the JavaScript code. Valid values include the following:
  • CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • CClientScript::POS_END : the script is inserted at the end of the body section.

Returns

boolean
whether the javascript file is already registered
public boolean
# isScriptRegistered( string $id, integer $position = CClientScript::POS_READY )

Checks whether the JavaScript code has been registered.

Checks whether the JavaScript code has been registered.

Parameters

$id
string
$id ID that uniquely identifies the JavaScript code
$position
integer
$position the position of the JavaScript code. Valid values include the following:
  • CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • CClientScript::POS_LOAD : the script is inserted in the window.onload() function.
  • CClientScript::POS_READY : the script is inserted in the jQuery's ready function.

Returns

boolean
whether the javascript code is already registered
protected
# recordCachingAction( string $context, string $method, array $params )

Records a method call when an output cache is in effect. This is a shortcut to Yii::app()->controller->recordCachingAction. In case when controller is absent, nothing is recorded.

Records a method call when an output cache is in effect. This is a shortcut to Yii::app()->controller->recordCachingAction. In case when controller is absent, nothing is recorded.

Parameters

$context
string
$context a property name of the controller. It refers to an object whose method is being called. If empty it means the controller itself.
$method
string
$method the method name
$params
array
$params parameters passed to the method

See

COutputCache
public static
# addPackage( string $name, array $definition )

Adds a package to packages list.

Adds a package to packages list.

Parameters

$name
string
$name the name of the script package.
$definition
array
$definition the definition array of the script package,

Returns

static
the CClientScript object itself (to support method chaining, available since version 1.1.10).

Since

1.1.9

See

CClientScript::packages.
Methods inherited from CApplicationComponent
getIsInitialized(), init()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
integer POS_HEAD 0
#

The script is rendered in the head section right before the title element.

The script is rendered in the head section right before the title element.

integer POS_BEGIN 1
#

The script is rendered at the beginning of the body section.

The script is rendered at the beginning of the body section.

integer POS_END 2
#

The script is rendered at the end of the body section.

The script is rendered at the end of the body section.

integer POS_LOAD 3
#

The script is rendered inside window onload function.

The script is rendered inside window onload function.

integer POS_READY 4
#

The body script is rendered inside a jQuery ready function.

The body script is rendered inside a jQuery ready function.

Properties summary
public boolean $enableJavaScript true
#

whether JavaScript should be enabled. Defaults to true.

whether JavaScript should be enabled. Defaults to true.

public array $scriptMap array()
#

the mapping between script file names and the corresponding script URLs. The array keys are script file names (without directory part) and the array values are the corresponding URLs. If an array value is false, the corresponding script file will not be rendered. If an array key is '.js' or '.css', the corresponding URL will replace all JavaScript files or CSS files, respectively.

This property is mainly used to optimize the generated HTML pages by merging different scripts files into fewer and optimized script files.

the mapping between script file names and the corresponding script URLs. The array keys are script file names (without directory part) and the array values are the corresponding URLs. If an array value is false, the corresponding script file will not be rendered. If an array key is '.js' or '.css', the corresponding URL will replace all JavaScript files or CSS files, respectively.

This property is mainly used to optimize the generated HTML pages by merging different scripts files into fewer and optimized script files.

public array $packages array()
#

list of custom script packages (name=>package spec). This property keeps a list of named script packages, each of which can contain a set of CSS and/or JavaScript script files, and their dependent package names. By calling CClientScript::registerPackage(), one can register a whole package of client scripts together with their dependent packages and render them in the HTML output.

The array structure is as follows:

array(
  'package-name'=>array(
    'basePath'=>'alias of the directory containing the script files',
    'baseUrl'=>'base URL for the script files',
    'js'=>array(list of js files relative to basePath/baseUrl),
    'css'=>array(list of css files relative to basePath/baseUrl),
    'depends'=>array(list of dependent packages),
  ),
  ......
)

The JS and CSS files listed are relative to 'basePath'. For example, if 'basePath' is 'application.assets', a script named 'comments.js' will refer to the file 'protected/assets/comments.js'.

When a script is being rendered in HTML, it will be prefixed with 'baseUrl'. For example, if 'baseUrl' is '/assets', the 'comments.js' script will be rendered using URL '/assets/comments.js'.

If 'baseUrl' does not start with '/', the relative URL of the application entry script will be inserted at the beginning. For example, if 'baseUrl' is 'assets' and the current application runs with the URL 'http://localhost/demo/index.php', then the 'comments.js' script will be rendered using URL '/demo/assets/comments.js'.

If 'baseUrl' is not set, the script will be published by CAssetManager and the corresponding published URL will be used.

When calling CClientScript::registerPackage() to register a script package, this property will be checked first followed by CClientScript::$corePackages. If a package is found, it will be registered for rendering later on.

list of custom script packages (name=>package spec). This property keeps a list of named script packages, each of which can contain a set of CSS and/or JavaScript script files, and their dependent package names. By calling CClientScript::registerPackage(), one can register a whole package of client scripts together with their dependent packages and render them in the HTML output.

The array structure is as follows:

array(
  'package-name'=>array(
    'basePath'=>'alias of the directory containing the script files',
    'baseUrl'=>'base URL for the script files',
    'js'=>array(list of js files relative to basePath/baseUrl),
    'css'=>array(list of css files relative to basePath/baseUrl),
    'depends'=>array(list of dependent packages),
  ),
  ......
)

The JS and CSS files listed are relative to 'basePath'. For example, if 'basePath' is 'application.assets', a script named 'comments.js' will refer to the file 'protected/assets/comments.js'.

When a script is being rendered in HTML, it will be prefixed with 'baseUrl'. For example, if 'baseUrl' is '/assets', the 'comments.js' script will be rendered using URL '/assets/comments.js'.

If 'baseUrl' does not start with '/', the relative URL of the application entry script will be inserted at the beginning. For example, if 'baseUrl' is 'assets' and the current application runs with the URL 'http://localhost/demo/index.php', then the 'comments.js' script will be rendered using URL '/demo/assets/comments.js'.

If 'baseUrl' is not set, the script will be published by CAssetManager and the corresponding published URL will be used.

When calling CClientScript::registerPackage() to register a script package, this property will be checked first followed by CClientScript::$corePackages. If a package is found, it will be registered for rendering later on.

Since

1.1.7
public array $corePackages
#

list of core script packages (name=>package spec). Please refer to CClientScript::$packages for details about package spec.

By default, the core script packages are specified in 'framework/web/js/packages.php'. You may configure this property to customize the core script packages.

When calling CClientScript::registerPackage() to register a script package, CClientScript::$packages will be checked first followed by this property. If a package is found, it will be registered for rendering later on.

list of core script packages (name=>package spec). Please refer to CClientScript::$packages for details about package spec.

By default, the core script packages are specified in 'framework/web/js/packages.php'. You may configure this property to customize the core script packages.

When calling CClientScript::registerPackage() to register a script package, CClientScript::$packages will be checked first followed by this property. If a package is found, it will be registered for rendering later on.

Since

1.1.7
public array $scripts array()
#

the registered JavaScript code blocks (position, key => code)

the registered JavaScript code blocks (position, key => code)

protected array $cssFiles array()
#

the registered CSS files (CSS URL=>media type).

the registered CSS files (CSS URL=>media type).

protected array $scriptFiles array()
#

the registered JavaScript files (position, key => URL)

the registered JavaScript files (position, key => URL)

protected array $metaTags array()
#

the registered head meta tags. Each array element represents an option array that will be passed as the last parameter of CHtml::metaTag().

the registered head meta tags. Each array element represents an option array that will be passed as the last parameter of CHtml::metaTag().

Since

1.1.3
protected array $linkTags array()
#

the registered head link tags. Each array element represents an option array that will be passed as the last parameter of CHtml::linkTag().

the registered head link tags. Each array element represents an option array that will be passed as the last parameter of CHtml::linkTag().

Since

1.1.3
protected array $css array()
#

the registered css code blocks (key => array(CSS code, media type)).

the registered css code blocks (key => array(CSS code, media type)).

Since

1.1.3
protected boolean $hasScripts false
#

whether there are any javascript or css to be rendered.

whether there are any javascript or css to be rendered.

Since

1.1.7
protected array $coreScripts array()
#

the registered script packages (name => package spec)

the registered script packages (name => package spec)

Since

1.1.7
public integer $coreScriptPosition CClientScript::POS_HEAD
#

Where the scripts registered using CClientScript::registerCoreScript() or CClientScript::registerPackage() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.

Where the scripts registered using CClientScript::registerCoreScript() or CClientScript::registerPackage() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.

Since

1.1.3
public integer $defaultScriptFilePosition CClientScript::POS_HEAD
#

Where the scripts registered using CClientScript::registerScriptFile() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.

Where the scripts registered using CClientScript::registerScriptFile() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.

Since

1.1.11
public integer $defaultScriptPosition CClientScript::POS_READY
#

Where the scripts registered using CClientScript::registerScript() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_READY.

Where the scripts registered using CClientScript::registerScript() will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_READY.

Since

1.1.11
Properties inherited from CApplicationComponent
$behaviors
Magic properties summary
public string $coreScriptUrl
#

The base URL of all core javascript files.

The base URL of all core javascript files.

Magic properties inherited from CApplicationComponent
$isInitialized
API documentation generated by ApiGen 2.8.0