Yii2 urlManager and the RedactorModule module

Briefly: Problem with the urlManager route. When urlManager is enabled, the redactor module is no longer able to load images.

In detail: For text editing, there is a module yii\redactor\RedactorModule The editor has the ability to add images to the text.

When you enable urlManager and try to add an image, two options appear errors

Http://site.lan/redactor/upload/image-json?_=1532085618974

Http://site.lan/redactor/upload/image

I understand that the problem is in the route, but I can't write it correctly.

Config file common

    'modules' => [
    'redactor' => [
        'class' => 'yii\redactor\RedactorModule',
        'uploadDir' => \Yii::getAlias('@frontend') . '/web/uploads/text_image/',
        'uploadUrl' => '@web/uploads/text_image',
        'imageAllowExtensions'=>['jpg','png','gif']
    ],
],

The module itself in the backend\view

    <?= $form->field($model, 'text')->widget(Redactor::className(),
    [
        'clientOptions' => [
            'lang' => 'ru',
            'buttonSource' => true,
            'plugins' => ['clips', 'fontcolor','imagemanager'],
            'minHeight' => '300px'
        ]
    ]
) ?>

UrlManager rules

       'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '/' => 'site/index',
            'about' => 'site/about',
            'contact' => 'site/contact',
            'login' => 'site/login',

            '<controller:\w+>/' => '<controller>/index',
            '<controller:\w+>/<action:(\w|-)+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:(\w|-)+>/<slug:([A-Za-z0-9-])+>' => '<controller>/<action>',
            '<controller:\w+>/<action:(\w|-)+>' => '<controller>/<action>',


        ],
    ],

The route that I tried to add, but to no avail

'<controller:\w+>/redactor' => '/redactor/upload/image',

Error shown by the built-in debugger

exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request: redactor/upload/' in E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\base\Controller.php:128
Stack trace:
#0 E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('', Array)
#1 E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('redactor/upload', Array)
#2 E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#3 E:\OSPanel\domains\site.lan\backend\web\index.php(17): yii\base\Application->run()
#4 {main}

Next exception 'yii\web\NotFoundHttpException' with message 'Страница не найдена.' in E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\web\Application.php:115
Stack trace:
#0 E:\OSPanel\domains\site.lan\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 E:\OSPanel\domains\site.lan\backend\web\index.php(17): yii\base\Application->run()
#2 {main}
Author: Ортем, 2018-07-20

1 answers

The solution to the problem was right under my nose. I had a route conflict.

Here is the next route that will work.

        '<controller:\w+>/redactor' => '/redactor/upload/image',
        '<controller:\w+>/' => '<controller>/index',
        '<controller:\w+>/<action:(\w|-)+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:(\w|-)+>' => '<controller>/<action>',

All I did was remove the extra routes, and add the following route

'<controller:\w+>/redactor' => '/redactor/upload/image',
 0
Author: Ортем, 2018-07-20 11:41:04