chainable Behavior adds fluent interface to any Yii components

  1. About
  2. Installation
  3. Usage
  4. Changelog
  5. License
  6. Resources

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

Resources

1 1
3 followers
468 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: Nayjest
Created on: Nov 4, 2010
Last updated: 7 years ago

Downloads

show all

Related Extensions