PHP - Yii - 动态属性 CActiveRecord

PHP - Yii - dynamic properties CActiveRecord

我有 class 个具有属性 {property}_{countrycode} 的人。 class 可以有 20 个属性,每个 属性 带有国家代码。 20x3 = class 中定义的 60 个属性。对于每种语言,我都需要在 class.

中手动定义它们
class Person extends CActiveRecord {

    public $name_sk;
    public $name_cz;     
    public $name_de;

    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    function tableName() {
        return 'person';
    }

}

问题:如何在class中动态generate/define这些属性?

示例:

public function __construct() {
    $langs = array('sk', 'cz', 'de');
    $properties = array('name', 'surname', 'age');
    foreach($langs as $lang) {
        foreach ($properties as $k => $value) {
            $this->{$value. "_". $lang} = null;
        }
    }
}

在Yii中1.x你can't。仅当您通过扩展覆盖 CActiveRecord._get() 时。