problem with custom CModel and set attributes

hello i made a model


class ApplicationVersion extends CModel {


    public $key;

    public $version;

    public $description;


    public function __construct($key = null, $version = null, $desc = null) {       

        $this->key = $key;

        $this->version = $version;

        $this->description = $desc;

    }


    public function attributeNames() {

        return array('key', 'version', 'description');

    }


    public function getPrimaryKey() {

        return $this->key;

    }

}

when i try to set it’s attributes with


$av = new ApplicationVersion;

$av->attributes = array('key' => 1, 'version' => '2', 'description' => 3);

it doesn’t work

$av->version, key and description are still null

the problem is that i can’t do this


if (isset($_GET['ApplicationVersion']))

    $model->attributes = $_GET['ApplicationVersion']

if i do it manually with


$model->version = $_GET['ApplicationVersion']['version'];

$model->description = $_GET['ApplicationVersion']['description'];

it’s ok

can anyone help me solve this problem?

thanks

not sure but i think you need


$av = new ApplicationVersion;

$av->setAttributes(array('key' => 1, 'version' => '2', 'description' => 3));

http://www.yiiframework.com/doc/api/CModel#setAttributes-detail

i’m way to inexperienced with yii but what i’ve seen before is that attributes weren’t set because they were ‘unsafe’

from the docs i get

Property Type Description Defined By

attributes array Returns all attribute values. CModel

so don’t know if you can set them this way too

i’ve added rules function


    public function rules() {

        return array(

            array('id, version, description', 'safe'),

        );

    }

and now it works!

thanks!