Package | system.web |
---|---|
Inheritance | class CWidgetFactory » CApplicationComponent » CComponent |
Implements | IApplicationComponent, IWidgetFactory |
Since | 1.1 |
Source Code | framework/web/CWidgetFactory.php |
return array( 'components'=>array( 'widgetFactory'=>array( 'class'=>'CWidgetFactory', ), ), )
return array( 'default'=>array( 'nextPageLabel'=>'>>', 'prevPageLabel'=>'<<', ), 'short'=>array( 'header'=>'', 'maxButtonCount'=>5, ), );In the above, there are two skins. The first one is the default skin which is indexed by the string "default". Note that CWidget::skin defaults to "default". Therefore, this is the skin that will be applied if we do not explicitly specify the CWidget::skin property. The second one is named as the "short" skin which will be used only when we set CWidget::skin to be "short".
Property | Type | Description | Defined By |
---|---|---|---|
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
enableSkin | boolean | whether to enable widget skinning. | CWidgetFactory |
isInitialized | boolean | Checks if this application component has been initialized. | CApplicationComponent |
skinPath | string | the directory containing all the skin files. | CWidgetFactory |
skinnableWidgets | array | list of widget class names that can be skinned. | CWidgetFactory |
widgets | array | widget initial property values. | CWidgetFactory |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
createWidget() | Creates a new widget based on the given class name and initial properties. | CWidgetFactory |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getIsInitialized() | Checks if this application component has been initialized. | CApplicationComponent |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the application component. | CWidgetFactory |
raiseEvent() | Raises an event. | CComponent |
Method | Description | Defined By |
---|---|---|
getSkin() | Returns the skin for the specified widget class and skin name. | CWidgetFactory |
whether to enable widget skinning. Defaults to false.
the directory containing all the skin files. Defaults to null, meaning using the "skins" directory under the current application's CWebApplication::viewPath.
list of widget class names that can be skinned. Because skinning widgets has performance impact, you may want to specify this property to limit skinning only to specific widgets. Any widgets that are not in this list will not be skinned. Defaults to null, meaning all widgets can be skinned.
widget initial property values. Each array key-value pair represents the initial property values for a single widget class, with the array key being the widget class name, and array value being the initial property value array. For example,
array( 'CLinkPager'=>array( 'maxButtonCount'=>5, 'cssFile'=>false, ), 'CJuiDatePicker'=>array( 'language'=>'ru', ), )
public CWidget createWidget(CBaseController $owner, string $className, array $properties=array (
))
| ||
$owner | CBaseController | the owner of the new widget |
$className | string | the class name of the widget. This can also be a path alias (e.g. system.web.widgets.COutputCache) |
$properties | array | the initial property values (name=>value) of the widget. |
{return} | CWidget | the newly created widget whose properties have been initialized with the given values. |
public function createWidget($owner,$className,$properties=array())
{
$className=Yii::import($className,true);
$widget=new $className($owner);
if(isset($this->widgets[$className]))
$properties=$properties===array() ? $this->widgets[$className] : CMap::mergeArray($this->widgets[$className],$properties);
if($this->enableSkin)
{
if($this->skinnableWidgets===null || in_array($className,$this->skinnableWidgets))
{
$skinName=isset($properties['skin']) ? $properties['skin'] : 'default';
if($skinName!==false && ($skin=$this->getSkin($className,$skinName))!==array())
$properties=$properties===array() ? $skin : CMap::mergeArray($skin,$properties);
}
}
foreach($properties as $name=>$value)
$widget->$name=$value;
return $widget;
}
Creates a new widget based on the given class name and initial properties.
protected array getSkin(string $className, string $skinName)
| ||
$className | string | the widget class name |
$skinName | string | the widget skin name |
{return} | array | the skin (name=>value) for the widget |
protected function getSkin($className,$skinName)
{
if(!isset($this->_skins[$className][$skinName]))
{
$skinFile=$this->skinPath.DIRECTORY_SEPARATOR.$className.'.php';
if(is_file($skinFile))
$this->_skins[$className]=require($skinFile);
else
$this->_skins[$className]=array();
if(($theme=Yii::app()->getTheme())!==null)
{
$skinFile=$theme->getSkinPath().DIRECTORY_SEPARATOR.$className.'.php';
if(is_file($skinFile))
{
$skins=require($skinFile);
foreach($skins as $name=>$skin)
$this->_skins[$className][$name]=$skin;
}
}
if(!isset($this->_skins[$className][$skinName]))
$this->_skins[$className][$skinName]=array();
}
return $this->_skins[$className][$skinName];
}
Returns the skin for the specified widget class and skin name.
public void init()
|
public function init()
{
parent::init();
if($this->enableSkin && $this->skinPath===null)
$this->skinPath=Yii::app()->getViewPath().DIRECTORY_SEPARATOR.'skins';
}
Initializes the application component. This method overrides the parent implementation by resolving the skin path.
Signup or Login in order to comment.