A
A
arab7892016-04-26 15:27:48
Yii
arab789, 2016-04-26 15:27:48

YII2. How to write the path correctly?

Installed the widget - asofter/yii2-imperavi-redactor .
Image loading problem.
Installed advanced template.
For the test, I created an upload folder in the root. Registered alias in common/config/bootstrap.php:

Yii::setAlias('@upload', dirname(dirname(__DIR__)) . '/upload');

The widget is included in the form:
<?php echo $form->field($model, 'body_en')->widget(
        \yii\imperavi\Widget::className(),
        [
            'plugins' => ['fullscreen', 'fontcolor', 'video'],
            'options'=>[
                'minHeight'=>400,
                'maxHeight'=>400,
                'buttonSource'=>true,
                'imageUpload'=>Yii::$app->urlManager->createUrl([Yii::getAlias('@upload')])
            ]
        ]
    ) ?>

When loading an image, the error in the console is: redactor.js:9004 POST admin.yii2-test.loc/D:/OpenServer/domains/yii2-tes... 403 (Forbidden). The rights of the folder are correct, I tried to create and modify the file from the same script.
If the path is written like this:
<?php echo $form->field($model, 'body_en')->widget(
        \yii\imperavi\Widget::className(),
        [
            'plugins' => ['fullscreen', 'fontcolor', 'video'],
            'options'=>[
                'minHeight'=>400,
                'maxHeight'=>400,
                'buttonSource'=>true,
                'imageUpload'=>Yii::getAlias('@upload')
            ]
        ]
    ) ?>

The error is this: redactor.js:9004 XMLHttpRequest cannot load file:///D:/OpenServer/domains/yii2-test.loc/upload. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Green_Cat, 2016-04-26
@arab789

There was a similar problem. Install https://github.com/vova07/yii2-imperavi-widget. The package already has ready-made GetAction and UploadAction. Just set the paths for loading images correctly

@
@gugozoha, 2016-04-26
_

it seems the web is missing on the way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question