Answer the question
In order to leave comments, you need to log in
How to solve the problem with transferring yii2 to hosting?
Good time of the day. I have been looking for a solution for the problem for 2 days now, maybe someone can help.
I used this module for access control in yii2 https://github.com/mdmsoft/yii2-admin
Everything worked on the local server, went to site.ru/rbac. On hosting it gives an error I Unknown Class – yii\base\UnknownClassException
used .htaccess in the /web folder
# Mod_Autoindex
<IfModule mod_autoindex.c>
# Disable indexes
Options -Indexes
</IfModule>
# Mod_Rewrite
<IfModule mod_rewrite.c>
# Enable symlinks
Options +SymLinksIfOwnerMatch
# Enable mod_rewrite
RewriteEngine On
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
</IfModule>
# Mod_Autoindex
<IfModule mod_autoindex.c>
# Disable Indexes
Options -Indexes
</IfModule>
# Mod_Rewrite
<IfModule mod_rewrite.c>
# Enable symlinks
Options +SymLinksIfOwnerMatch
# Enable mod_rewrite
RewriteEngine On
# Redirect all requests to web
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*)$ web/$1
</IfModule>
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'language' => 'ru',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'eSF2bcJ',
'baseUrl'=> '',
],
'authManager' => [
'class' => 'yii\rbac\DbManager', // or use 'yii\rbac\DbManager'
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'loginUrl' => ['site/login'],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager'=> [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
],
],
'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' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
],
'rbac' => [
'class' => 'mdm\admin\Module',
'controllerMap' => [
'assignment' => [
'class' => 'mdm\admin\controllers\AssignmentController',
/* 'userClassName' => 'app\models\User', */
'idField' => 'user_id',
'usernameField' => 'username',
],
],
'layout' => 'left-menu',
'mainLayout' => '@app/views/layouts/admin.php',
],
],
'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
'site/*',
'admin/*',
'rbac/*',
]
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question