installing yii2-rbac error You have wrong authManager configuration - yii2

I install yii2-rbac following this site page: https://github.com/dektrium/yii2-rbac/blob/master/docs/installation.md .
I do it second time. First time I have done, but I wrote in the config/web.php file:
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
],
//'rbac' => 'dektrium\rbac\RbacWebModule',
'rbac' => 'dektrium\rbac\RbacConsoleModule',
],
I did not know, that 'rbac' => 'dektrium\rbac\RbacConsoleModule' it must write in the console.php (not in web.php).
'authManager' => [
'class' => 'yii\rbac\DbManager',
//'defaultRoles' => ['guest'],
],
`
This code I have wrote in both config files: web.php and console.php, but in the web.php I have wrote 'rbac' => 'dektrium\rbac\RbacConsoleModule' and in console.php I have not wrote it, but all worked: yii2-rbac has been installed succeful. And all transaction have passed succeful. But 'rbac' => 'dektrium\rbac\RbacConsoleModule' in web.php seems to me wrong. It isn't web module, it is console module. Then I have rollbacked transactions (migrate/down) and I have removed rbac at all by removing from composer.json "dektrium/yii2-rbac": "1.0.0-alpha#dev" declaration. All has been removed.
Than I began to install rbac second time. After composer installation I have wrote in the web.php:
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
],
'rbac' => 'dektrium\rbac\RbacWebModule',
//'rbac' => 'dektrium\rbac\RbacConsoleModule',
],
and in console.php I have wrote:
'modules' => [
'rbac' => 'dektrium\rbac\RbacConsoleModule',
],
The site on yii2 don't work after it!!! I have changed in the web.php "...RbacConsoleModule". Site works. Why it don't work with RbacWebModule? Then I tried to apply transactions, that I have rollbacked before, but raise error: You have wrong authManager configuration
enter image description here
What can I do? Help me. Ecscuse me for my English. I'm from Russia.
my console.php:
$config = [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'authManager' => [
'class' => 'yii\rbac\DbManager',
//'defaultRoles' => ['guest'],
]
],
'modules' => [
'rbac' => 'dektrium\rbac\RbacConsoleModule',
],
//....
my web.php:
//This all in $component
'db' => require(__DIR__ . '/db.php'),
'authManager' => [
'class' => 'yii\rbac\DbManager',
//'defaultRoles' => ['guest'],
],
],
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
],
//'rbac' => 'dektrium\rbac\RbacWebModule',
'rbac' => 'dektrium\rbac\RbacConsoleModule',
],

That all! The problem has been decided. It must write authManager section to modules, not in components:
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
//'defaultRoles' => ['guest'],
]
//'rbac' => 'dektrium\rbac\RbacWebModule',
'rbac' => 'dektrium\rbac\RbacConsoleModule',
]

you need write that:
'components' => [
'authManager' => [
'class' => 'dektrium\rbac\components\DbManager',
'defaultRoles' => ['users'],
],
...

Related

yii2 how to view the logs of another .log file

I am using the yii2 framework with the 'queue' extension. This extension may fail, which is saved in the log file, and I would like to view the error in a specific view.
I was able to log errors into a specific .log file, so the real question is, how can I view errors from another log file?
Yii framework use category distinguish log file
configļ¼š
return [
'bootstrap' => ['log'],
'timeZone' => 'PRC',
'components' => [
'log' => [
'targets' => [
//default
[
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning'],
],
//especially
[
'class' => 'yii\log\DbTarget',
'levels' => ['error'],
'categories' => ['yii\db\*'],//The point
'logFile'=>'log.txt',//you custom file
],
//especially2
[
'class' => 'yii\log\DbTarget',
'levels' => ['error'],
'categories' => ['app\models'],//The point
'logFile'=>'log.txt',//you custom file
],
//especially3
[
'class' => 'yii\log\DbTarget',
'levels' => ['error'],
'categories' => ['abc'],//The point
'logFile'=>'log.txt',//you custom file
],
],
],
],
];
Use it
Yii::trace('db error');
Yii::trace('start calculating average revenue', __METHOD__);
Yii::trace('start calculating average revenue', 'abc');
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
'error' =>
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
'categories' => ['yii\queue\Queue'],
'logFile' => '#runtime/logs/error.log',
//'enabled' => YII_DEBUG,
//'exportInterval' => 1,
],
],
],

Why routes is empty in mdmsoft/yii2-admin?

I configured mdmsoft/yii2-admin in yii2 basic template
but routes list is empty. why ?
Confugrations
'modules' => [
...
'admin' => [
'class' => 'mdm\admin\Module',
'layout' => 'right-menu', // avaliable value 'left-menu', 'right-menu' and 'top-menu'
'mainLayout' => '#app/views/layouts/main.php',
]
...
],
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
'defaultRoles' => ['guest']
]
...
]

Yii2 authClientCollection showing error Missing required parameter "id" when instantiating "yii\authclient\AuthAction"

To add facebook login in my website in config/main.php i add below code and and
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => '1956343439487263',
'clientSecret' => 'c72a44343439f1ec8bc7b671e935e3c8',
],
],
],
Add configuration in site controller behaviors like below but show that error
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallback'],
],

How can I use Yii2 Glide

I already use yii2-file-kit. And now I want to resize my thumbnail by glide but I'be got error in log
"NetworkError: 500 Internal Server Error - http://storage.local/cache/1/iApQj79NQCji2TWsLZppiCQ8lbdgAPBz.jpg?w=100"
Here is my config
'components' => [
'cache' => [
'class' => 'yii\caching\DummyCache',
],
'fileStorage' => [
'class' => '\trntv\filekit\Storage',
'baseUrl' => '#storageUrl/source',
'filesystem' => [
'class' => 'common\components\filesystem\LocalFlysystemBuilder',
'path' => '#storage/web/source'
],
'as log' => [
'class' => 'common\behaviors\FileStorageLogBehavior',
'component' => 'fileStorage'
]
],
'glide' => [
'class' => 'trntv\glide\components\Glide',
'sourcePath' => '#storage/web/source',
'cachePath' => '#storage/cache',
'urlManager' => 'urlManagerStorage',
'maxImageSize' => 4000000,
'signKey' => 'pe4AJmRcBFbXfZvsk93VN'
],
And in my view
<?= Html::img(
Yii::$app->glide->createSignedUrl([
'glide/index',
'path' => $model->productAttachments[0]->path,
'w' => 100
], true),
['class' => 'article-thumb img-rounded pull-left']
) ?>
I just look at Starter-Kit config and there is the same config as I see. storage config are the same as yii2-starter-kit
Can you show debug for more information. Or you can output image by
Url::base(true).'/glide?path='.$path.'&w='.$w.'&h='.$h.'&fit=crop';

application configuration file path of yii2

I installed yii2 and then added gii to yii2 from this link.
return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
// ...
],
// ...
];
I want to plce this code in application configuration file where it is located?
Application configuration file reside in: project_name/config/web.php
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class'=>'yii\gii\Module',
'allowedIPs'=>['127.0.0.1','192.168.1.*'],
];
You will find a file web.php which is in in the config folder located at your root app folder, the file will contain something like the following:
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'name' => 'My Cool App',//If this line exists change it to your new app name otherwise add it.
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '_4wmrZYaMY7joBAFHrXKpEIFvs9m9S_I',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
],
'params' => $params,
];
if(YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
Notice I've added a line: 'name' => 'My Cool App',
Hope this helps.