Difference between #4 and #5 of
Yii configuration: Dynamic & User dependent

Changes

Title unchanged

Yii configuration: Dynamic & User dependent

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

config, theme, widget configuration

Content changed

[...]
/**
* Provides an instance providing a user property when called.
*
* @param string $property Same as second parameter in CHtml::value
* @param string $default Default value
, evaluated as PHP code (inside string, so null must be written as "null"). * @param string $template If provided '{val}' in the template is replaced with the User property. * @return mixed_UserProperty Property returned by User model or default if null or empty string.
*/
public static function getProperty($property,$default=null,$template=null) {
[...]
$defaultexpression='';
}
$val="CHtml::value(
Yii::app()->uAppUtils::getRealUser(),'$property')"; if($template!==null) { $val2="strtr('$template',array('{val}'=>$val))if(\"{\$this->val}\"!=='') \$this->val=strtr('$template',array('{val}'=>\$this->val));";
 
            } else {
 
                $val2="
"; } $code="class $propertyclass {
 
                    private \$val;
extends _UserProperty{ privateotected function _val() { if(!isset(\$this->val)) { \$this->val=$val;
 
                         
$val2 $defaultexpression } return \$this->val; }     public function __toString() {
 
                        \$r=\$this->_val()
}";
 
            //Yii::trace($code);
 
            //if($property==='propertytocheck') throw new CException($code);
 
            eval($code);
 
            self::$inst[$propertyclass]=new $propertyclass
; }
 
        return \$r;
 
                    }
 
                
return self::$inst[$propertyclass];
 
    }
 
}
 
 
/**
 
 * Abstract class for User Property.
 
 */
 
abstract class _UserProperty {
 
    protected $val;
 
 
    abstract protected function _val();
 
 
    public function __toString() {
 
        $r=$this->_val();
 
        return $r;
 
    }
 
public function __call(\$name,\$parameters) {                  return call_user_func_array(array(\$this->_val(),\$name),\$parameters);                    }
 
                

 
    }
 
public function __get(\$name) {                  return \$this->_val()->\$name;                 }
 
 
                }";
 
            //print strtr($code,array("\n"=>'<br />'));
 
            eval($code);
 
            self::$inst[$propertyclass]=new $propertyclass;
 
        }
 
        return self::$inst[$propertyclass];
 
    }
 
} } ```
1 0
1 follower
Viewed: 13 254 times
Version: 1.1
Category: How-tos
Written by: le_top
Last updated by: le_top
Created on: Oct 16, 2014
Last updated: 10 years ago
Update Article

Revisions

View all history