使用 Yii 权限模块创建新角色时保存其他数据


Save additional data while creating new role with Yii Rights Module

我有 Yii 权限模块 http://www.yiiframework.com/extension/rights/

我想要的是保存其他数据,即在创建角色时在 authItem 表中创建角色的用户的 id。通过浏览代码,我发现AuthItemController中的以下行.php可以帮助我

// Create the item
$item = $this->_authorizer->createAuthItem($formModel->name, $type, $formModel->description, $formModel->bizRule, $formModel->data);

我不明白如何使用此代码存储其他数据。请帮助我。

好的,通过更多的解决方法,我找到了解决方案。

我在身份验证项表中创建了新字段created_by。

RAuthItemBehavior 中添加了此函数.php

/**
     * add the id of user - who created the role - in db
     * @return doesn't return anything
     */
    public function addItemCreator()
    {
        Yii::app()->db->createCommand()
        ->update('authitem', array(
            'created_by'=>Yii::app()->user->id,
        ), 'name=:name', array(':name'=>$this->owner->name));
    }

并在 AuthItemController 上调用了该函数.php通过添加此行在创建操作中

$item->addItemCreator();

$item = $this->_authorizer->attachAuthItemBehavior($item);

欢迎任何改进建议。