About ¶
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 (fluent interface).
Installation ¶
Place EChainableBehavior.php
to your extension directory (yourWebRoot/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
Changelog ¶
Nov 11 2010: Support of calling owner methods, refactoring
Nov 4 2010: Initial release
License ¶
New BSD license
author: Vitaliy Stepanenko mail@vitaliy.in
:)
Example with clientScript isn't actual now, because Qiang added 'return $this' to methods of CClientScript mega-operativley after reading my issue in google.code :)
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.