我已经安装了 yii-user 并且想要使用配置文件字段。我通常检索我需要的字段,如下所示:
Yii::app()->getModule('user')->user()->profile->firstname
但问题是如何从另一个 Controller 更改配置文件表字段,例如名字、姓氏等?
Yii-user模块本身已经创建了profiles表。
最佳答案
经过很多麻烦和深入研究代码,我终于成功了。
我实际需要的是使用 Yii::app()->getModule('user')->user()->profile
加载配置文件模型,然后使用 setAttributes
设置配置文件字段值。最后但并非最不重要的一点是使用 save()
来保存我的更改。
$profileModel = Yii::app()->getModule('user')->user()->profile;
$profileModel->setAttributes(array('balance'=>1200));
$profileModel->save();
这可能对其他人有帮助。 ;-)
干杯!
关于php - Yii-User 模块中的配置文件字段修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614414/