Closed RSalo closed 9 years ago
Do you have rule class?
@samdark yes, i do.
namespace app\rbac;
use yii\rbac\Item;
use yii\rbac\Rule;
class AuthorRule extends Rule
{
public $name = 'isAuthor';
public function execute($user, $item, $params)
{
return isset($params['post']) ? $params['post']->createdBy == $user : false;
}
}
But maybe i'm doing something wrong?
Doesn't seem so. Looks weird.
I hope, this information have to help solved my problem: Data from auth_rule table:
name : isAuthor
data : O:19:"app\rbac\AuthorRule":3:{s:4:"name";s:8:"isAuthor";s:9:"createdAt";i:1444865585;s:9:"updatedAt";i:1444865585;}
created_at : 1444865585
updated_at : 1444865585
Yii 2.0.5 PHP 5.6.1 (cli) Loaded extensions:
Core
ctype
curl
date
dom
ereg
fileinfo
filter
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xdebug
xml
xmlreader
xmlwriter
zlib
@RSalo Could you try to change the serialized data in DB rules table to this: \app\rbac\AuthorRule
(i added \
at the beggining of the class name)
@SilverFire i added in DB "\" and right now get error
can you post
on Gist ( https://gist.github.com/ )
@duynguyen0511 yes of course https://gist.github.com/RSalo/1b97b52f1ccc011a63e7
@RSalo
your AuthorRule class use "namespace app\rbac", but you place it under "/config/rbac/"
you can
or
The point is your namespace must match the file location or Yii2 cant auto-load your AuthorRule class
@duynguyen0511 changed https://gist.github.com/RSalo/cf545b689f996aa33dcb and have the same error https://cloud.githubusercontent.com/assets/4490762/10672457/0ce20df0-78f9-11e5-94d5-0f17e83df409.png
@RSalo
would you remove your rule and re-add them again ?
e.g. remove entry in auth_rule (the rule itself), remove entry in auth_item (permission that use the rule)
Then, create new rule, then add it to permission .
It should work.
@duynguyen0511 no i don't it. one moment, i remove all tables and will create a new
Probably, i found where is problem. In AuthorRule we have namespace "app\rbac\AuthorRule" that = "/srv/www/htdocs/shelter/config/rbac/AuthorRule.php", but yii in vendor have other path to my rule at the same namespace "/srv/www/htdocs/shelter/rbac/AuthorRule.php".
I see the only one way - hard write correct "@app" alias in bootstrap file. Or have you others ways to solved this issue?
You're wrong.
@app
alias points to /src/www/htdocs/shelter/
, so
app\rbac\AuthorRule
namespace points to the /src/www/htdocs/shelter/rbac/AuthorRule.php
If you want to store the rule file in the config directory, you have to change file namespace to app\config\rbac
Is it clear for you?
Hello everybody! Have issue with RBAC unserialize. I'm trying to check permission access but getting error "Rule not found : isAuthor". All actions i did step by step as in manual. I'll be grateful for any help!