【问题标题】:Profile Field Modification In Yii-User ModuleYii 用户模块中的配置文件字段修改
【发布时间】:2014-07-11 16:06:14
【问题描述】:

我已经安装了 yii-user 并且想要使用配置文件字段。我通常检索我需要的字段如下:

Yii::app()->getModule('user')->user()->profile->firstname

但问题是如何从另一个控制器更改配置文件表字段,如名字、姓氏等?

Yii-user 模块本身已经创建了 profiles 表。

【问题讨论】:

  • 也许 $user = Yii::app()->getModule('user')->user(); $用户->名字=1; $user->save();
  • @Konstantin,它不起作用,因为您无权通过 $user 访问配置文件字段。它给出了错误。

标签: php yii yii-extensions


【解决方案1】:

经过大量麻烦并深入研究代码后,我终于管理了它。
我真正需要的是使用Yii::app()->getModule('user')->user()->profile 加载配置文件模型,然后使用setAttributes 设置配置文件字段值。最后但并非最不重要的一点是使用save() 来保存我的更改。

            $profileModel = Yii::app()->getModule('user')->user()->profile;
            $profileModel->setAttributes(array('balance'=>1200));
            $profileModel->save();   

它可能会帮助其他人。 ;-)
干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 2012-12-25
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    相关资源
    最近更新 更多