CBehavior
CBehavior is a convenient base class for behavior classes.
Public Properties
Property |
Type |
Description |
Defined By |
enabled | boolean | whether this behavior is enabled | CBehavior |
owner | CComponent | the owner component that this behavior is attached to. | CBehavior |
Property Details
public boolean getEnabled()
public void setEnabled(boolean $value)
whether this behavior is enabled
public CComponent getOwner()
the owner component that this behavior is attached to.
Method Details
public void attach(CComponent $owner) |
$owner | CComponent | the component that this behavior is to be attached to. |
Attaches the behavior object to the component. The default implementation will set the owner property and attach event handlers as declared in events. This method will also set enabled to true. Make sure you've declared handler as public and call the parent implementation if you override this method.
public void detach(CComponent $owner) |
$owner | CComponent | the component that this behavior is to be detached from. |
Source Code: framework/base/CBehavior.php#62 (
show)
public function detach($owner)
{
foreach($this->events() as $event=>$handler)
$owner->detachEventHandler($event,array($this,$handler));
$this->_owner=null;
$this->_enabled=false;
}
Detaches the behavior object from the component. The default implementation will unset the owner property and detach event handlers declared in events. This method will also set enabled to false. Make sure you call the parent implementation if you override this method.
public array events() |
{return} | array | events (array keys) and the corresponding event handler methods (array values). |
Declares events and the corresponding event handler methods. The events are defined by the owner component, while the handler methods by the behavior class. The handlers will be attached to the corresponding events when the behavior is attached to the owner component; and they will be detached from the events when the behavior is detached from the component. Make sure you've declared handler method as public.
public boolean getEnabled() |
{return} | boolean | whether this behavior is enabled |
public CComponent getOwner() |
{return} | CComponent | the owner component that this behavior is attached to. |
public void setEnabled(boolean $value) |
$value | boolean | whether this behavior is enabled |
Source Code: framework/base/CBehavior.php#89 (
show)
public function setEnabled($value)
{
$value=(bool)$value;
if($this->_enabled!=$value && $this->_owner)
{
if($value)
$this->_attachEventHandlers();
else
{
foreach($this->events() as $event=>$handler)
$this->_owner->detachEventHandler($event,array($this,$handler));
}
}
$this->_enabled=$value;
}