Cant resolves site / index after separation in two "modules"

I wanted to separate the manager and the interface:

root / manager / controllers / SiteController.php  

namespace manager\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;

class SiteController extends Controller
{

    public function actionIndex()
    {
        echo 'hallo';
        //return $this->render('index');
    }
}

root / manager / configuration / web.php  

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'manager\controllers',
    'bootstrap' => ['log'],
    'modules' => [
        'manager' => [
            'class' => 'manager\Module',
        ],
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'X',
        ],
        '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.
        ],
        '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' => [
                '' => 'site/index',
                'fragebogen/erstellung/<id>' => 'questionary/creation',
                'fragebogen/erstellung' => 'questionary/creation',
                'auftraege-importieren' => 'upload/jobs',
                'auftraege-erfolgreich-importiert' => 'upload/jobssuccess',
            ],
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // 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;

root / manager / web / index.php

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

(new yii\web\Application($config))->run();

And I get this error:

exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/web/ErrorHandler.php(80): yii\base\Module->runAction('site/error')
#1 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/ErrorHandler.php(95): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#2 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#3 {main} Previous exception: exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/index".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('site/index', Array)
#1 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /kunden/xxx/xxx/manager/web/index.php(12): yii\base\Application->run()
#3 {main}

Next exception 'yii\web\NotFoundHttpException' with message 'Unable to resolve the request "site/index".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/web/Application.php:95 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /kunden/xxx/xxx/manager/web/index.php(12): yii\base\Application->run()
#2 {main}

enter image description here

+4
source share
6 answers

Is this topic allowed? If not, check your boot file in general /config/bootstrap.php. If your application tries to use a path alias and cannot be resolved, you will receive the following exception!

exception 'yii \ base \ InvalidRouteException' with the message "Unable to resolve the site / error request.

Yii:: setAlias ​​('backend', dirname (dirname (DIR)). 'Backend'); Yii:: setAlias ​​('backend', dirname (dirname (DIR)). '/Backend');

+4

URL, , , , . . URL Yii2


https://github.com/Mihai-P/yii2-core

, , controllerNamespace, . - : https://github.com/Mihai-P/yii2-core/blob/master/Module.php

'class' = > 'manager\Module'

, , ? , ? , , , - . Yii, , .

https://github.com/Mihai-P/yii2-core#note-2

0

, Namespace Yii2?

?

'controllerMap' => [
    'site' => 'manager\controllers\SiteController',
],
0

, ,

'modules' => [
    'manager' => [
        'class' => 'manager\Module',
    ],
],

, . .

enablePrettyUrl URL- false , URL-.

bootstrap.php manager, , .

, SiteController , site/error .

: , , . , , - . , , ...

0

, . , . :

\Yii::setAlias(’@manager’, dirname(__FILE__).'/..');

, - , .

0

I noticed that this error usually occurs due to an incorrect configuration or because of case-sensitive class names and namespaces. In my case, the error was caused by the configuration of the ii8n component. I used the following configuration

    'i18n' => [
        'translations' => [
            '*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@backend/messages',
                'sourceLanguage' => 'en-US',
                'forceTranslation'=> true,
            ],
        ],
    ],

The problem was resolved after deleting the configuration.

0
source

All Articles