aamirkh521 / yii-user

Automatically exported from code.google.com/p/yii-user
0 stars 0 forks source link

Add posibility to configure model behaviors #54

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I use this feature to implement alot of project-specific business logics 
without modification of yii-user module at each project, this is critically 
important feature and it would be great to add it to Yii-user.
Patch:

1) Add to UActiveRecord:
public function behaviors(){return 
Yii::app()->getModule('user')->getBehaviorsFor(get_class($this));}

(or Yii::app()->getController()->getModule() instead of 
Yii::app()->getModule('user') to remove depencency from module name, this 
variant isn't tested by me, first variant works well)

2) Add to user module:
public $componentBehaviors=array();
public function getBehaviorsFor($componentName){
        if (isset($this->componentBehaviors[$componentName]))
        {
            return $this->componentBehaviors[$componentName];
        }else{
            return array();
        }
}

3) We can configure it:
'user'=>array(
  'class'=>'application.modules.user.UserModule',
  'componentBehaviors'=>array(  
    'Profile'=>array(                                     
       'myProjectSpecificBusinessLogics'=>array('class'=>'Proj130UserBehavior'),
     ),                          
  ),
),

In beaviors I usually implement events such as afterSave, beforeValidate, etc.

Original issue reported on code.google.com by vitaliy.step on 24 Jan 2011 at 9:53

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r105.

Original comment by mish...@gmail.com on 16 Feb 2011 at 1:06