尝试实现RBAC过程中遇到下面的问题:
(测试环境:os: xp webserver:apache 2.2.11 php:5.2.9 sqlserver:postgresql 8.3.7)
测试过程:
1.在数据库中创建table user并使用shell创建model和crud,使用shell创建用户alex并修改protected/components/UserIdentity.php使其实现正常登陆。
2.使用framework/web/auth/schema.sql 创建rbac相关的三个table。
3.按照rabc文档的样例使用shell创建相应的授权等级,过程如下:
4.修改UserController.php,在accessRules中将admin和delete两个action对应的'users'=>array('admin')更改为'roles'=>array('admin')。
当访问user/admin时,出现以下错误
Quote
描述
CDbCommand 无法执行 SQL 语句: SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = integer
LINE 1: …hItem t1, AuthAssignment t2 WHERE name=itemname AND userid=1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
这是postgresql的log
Quote
%t HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
%t STATEMENT: SELECT name, type, description, t1.bizrule, t1.data, t2.bizrule AS bizrule2, t2.data AS data2 FROM AuthItem t1, AuthAssignment t2 WHERE name=itemname AND userid=1;
查看数据库,发现table authassignment的userid字段类型为vchar,而实际产生的sql中userid为integer,看起来这似乎是引起问题的原因。
assign在数据库中生成的纪录中userid也确实是字符串类型的用户名而非integer类型的用户id
这是我实现的过程中有错误才造成的这个特殊情况?
还是我应该将userid字段修改为integer并尝试在assign时的userid参数转换为实际的用户id呢
还是想办法让accessRules或者checkAccess中的userid参数变为字符串的username?
刚接触Yii不久,请大家多多指教。感谢!