About this extension
EChainableBehavior
is Yii extension that gives posibility to use jQuery-like chainable style of working with public component properties, class methods that not return important data or AR attributes
Installation
Place EChainableBehavior.php
to protected/extensions
Usage
example:
$user->attachBehavior('chain',array('class'=>'ext.EChainableBehavior'));
$id = $user->chain
->email('mail@example.com') # set $user->email
->firstName('Ivan') # set $user->firstName
->lastName('Ivanov')
->id(); # if no attributes passed then return value
It's convenient to use with clientScript
to make code of views more clean:
$res=Yii::app()->clientScript->chain
->registerScriptFile('script1.js')
->registerScriptFile('script2.js')
->registerScriptFile('script3.js')
->coreScriptUrl(); //will return clientScript->coreScriptUrl
Before using of chainable behavior you need to configure this component in your application configuration:
'components'=>array(
'clientScript'=>array(
'behaviors'=>array(
'chain'=>'ext.EChainableBehavior'
)
),
....
),
If last parameter passed to method is equal to constant ECB_RETURN then method result will returned instead of $this
author Vitaliy Stepanenko