Changing specific symbol of YII cactiverecord model's attribute

46 views Asked by At

How to change specific symbol of YII cactiverecord model's attribute ? Dont understand why it doesnt work:

echo $model->attr; // aaa
$model->attr[1] = 'b';
echo $model->attr; // aaa
1

There are 1 answers

1
Goodnickoff On BEST ANSWER

Use substr_replace function:

echo $model->attr; // aaa
$model->attr = substr_replace($model->attr, 'b', 1, 1);
echo $model->attr; // aba

http://www.php.net/manual/en/function.substr-replace.php

Also you can use this approach:

$newValue = $model->attr[1] = 'b';
$model->attr = $newValue;
echo $model->attr; // aba

Your example does not work because actually $this->AttributeName execute CActiveRecord::getAttribute('AttributeName') method and not affect original value.