简体   繁体   中英

Changing specific symbol of YII cactiverecord model's attribute

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM