我在配置上更改了我的@keyframes "blink" {
from, to {
color: transparent;
}
50% {
color: black;
}
}
,看起来像这样。这是根据我的默认控制器$defaultRoute
?我收到404错误
主要-local.php
AdminController
我在localhost上测试我的应用程序,但我的主配置仍然是默认的root。
main.php
<?php
$config = [
'defaultRoute' => 'admin/index',
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'b0pQ7nOuVjCprrOGrTarC-ErVMHUWQbb',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
return $config;
我的<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'defaultRoute' => 'admin/index',
'modules' => [],
'components' => [
'user' => [
'identityClass' => 'backend\models\Admin',
'enableAutoLogin' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'admin/error',
],
],
'params' => $params,
];
包含以下代码:
.htaccess
此处还有我的Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if request begins with /admin remove admin and ad /backend/web/
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin\/?(.*) /backend/web/$1
# other requests add /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|admin)
RewriteRule (.*) /frontend/web/$1
# if frontend request
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php
# if backend request
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /backend/web/index.php
代码:
AdminController
我是否将<?php
namespace backend\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use backend\models\LoginForm;
use yii\filters\VerbFilter;
class AdminController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionIndex()
{
return $this->render('index');
}
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
}
插入错误的文件中。我不想在框架代码本身上这样做,所以我非常感谢你的帮助。
答案 0 :(得分:1)
您的展示位置对于'defaultRoute'属性是正确的。
您是否尝试将其设置为除.htaccess中没有规则的admin / index以外的其他内容?
如果它有效,那么你知道你的.htaccess与它有冲突,我会尝试以下内容。
我将删除自定义.htaccess规则(我将其称为块1,2,4),一次一个地离开其他块。 如果这不起作用,那么删除1&amp; 2在一起;然后我会尝试所有。通过这样做,它应该可以帮助您缩小问题范围。
请注意,如果您确实删除了规则,则必须相应地调整您的网址以进行测试(例如,将后端/网络/回添加到您的网址,以便您的AppName / backend / web可以将您带到管理员/索引)您将无法从您的URL中删除后端/ Web的规则。
如果它不是.htaccess,那么它必须是你的应用程序中的一些其他自定义代码。
这是删除.index
的.htaccess规则#Use if on shared hosting and this not in the root folder.
#RewriteBase /
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
答案 1 :(得分:-1)
将其从main-local.php中取出
在main.php内部,它位于正确的位置。
'defaultRoute' => 'admin/index',
请注意,您需要将AdminController放在代码中此语句中指定的@backend / controllers目录中。
'controllerNamespace' => 'backend\controllers',