K
K
kanly2020-05-22 23:02:44
This
kanly, 2020-05-22 23:02:44

How to solve the error in the transition to the admin panel?

The guys installed yii2 advanced. Everything works fine in the frontend, but if I want to go to the backend through /admin, output this:

An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in C:\OpenServer\domains\yii-application\backend\config\main.php on line 1. in C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
#0 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders()
#1 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\ErrorHandler.php(136): yii\web\Response->send()
#2 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\ErrorHandler.php(123): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\ErrorException))
#4 {main}
Previous exception:
yii\base\ErrorException: session_start(): Cannot send session cookie - headers already sent by (output started at C:\OpenServer\domains\yii-application\backend\config\main.php:1) in C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Session.php:137
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'session_start()...', 'C:\\OpenServer\\d...', 137, Array)
#1 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Session.php(137): session_start()
#2 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Session.php(642): yii\web\Session->open()
#3 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\User.php(414): yii\web\Session->set('__returnUrl', 'http://yii-appl...')
#4 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\User.php(446): yii\web\User->setReturnUrl('http://yii-appl...')
#5 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\filters\AccessControl.php(156): yii\web\User->loginRequired()
#6 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\filters\AccessControl.php(140): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#7 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\ActionFilter.php(77): yii\filters\AccessControl->beforeAction(Object(yii\base\InlineAction))
#8 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#9 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\Component.php(627): call_user_func(Array, Object(yii\base\ActionEvent))
#10 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\Controller.php(276): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#11 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Controller.php(188): yii\base\Controller->beforeAction(Object(yii\base\InlineAction))
#12 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\Controller.php(155): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#13 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('', Array)
#14 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('', Array)
#15 C:\OpenServer\domains\yii-application\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#16 C:\OpenServer\domains\yii-application\backend\web\index.php(17): yii\base\Application->run()
#17 {main}


To be honest, I don't understand why? If anyone understands please tell me. I wanted to install the latest version of yii2, before there was no such error

if it was related to httaccess, here in backend/web:
# use mod_rewrite for pretty URL support
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


and in the very root of the site:
#Options +FollowSymLinks
#IndexIgnore */*
#RewriteEngine on
#
## Если запрос начинается с /admin, то заменяем на /backend/web/
#RewriteCond %{REQUEST_URI} ^/admin
#RewriteRule ^admin\/?(.*) /backend/web/$1
#
## Добавляем другой запрос /frontend/web/$1
#RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|admin)
#RewriteRule (.*) /frontend/web/$1
#
## Если frontend запрос
#RewriteCond %{REQUEST_URI} ^/frontend/web
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /frontend/web/index.php
#
## Если backend запрос
#RewriteCond %{REQUEST_URI} ^/backend/web
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /backend/web/index.php
AddDefaultCharset UTF-8

Options -Indexes

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin(\/?.*)$ backend/web/$1 [L]

RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(\/?.*)$ frontend/web/$1 [L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mylistryx, 2020-05-22
@kanly

Google. First line.
Headers already sent in C:\OpenServer\domains\yii-application\backend\config\main.php on line 1 - what is written?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question