2

I'm trying to update a row when a user gets an authentication key, but my $model->attributes remain empty when I save my $data array to them. Here's what I have:

public function redeemKey($key,$subscription_id){
    $key = $this->findbyAttributes(array('key'=>$key));
    if(count($key) === 1){
        if(is_null($key['date_used'])){
            $model = new NewsItemPass;
            $model->attributes = $key;
            echo "<pre>",print_r($model->attributes),"</pre>";
        }
    }
}

prints out to

Array
(
    [id] => 
    [key] => 
    [date_created] => 
    [date_used] => 
    [date_expired] => 
    [news_subscription_id] => 
    [duration] => 
)

what am I overlooking?

1 Answer 1

3

$model->attributes = $key; will not work, because $this->findbyAttributes returns a type of CActiveRecord(CModel).

To copy attributes from one model to another, use the setAttributes() method with the second flag set to false.

$model->setAttributes($key->attributes, false);

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.