0

Вобщем нужно сделать модуль на yii2 который будет работать как RestFull. Вот часть конфигурации

     'urlManager'=>[

        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            ['class' => 'yii\rest\UrlRule', 'controller' => ['v1/books','v1/authors']],
        ],

    ],

Но при такой конфигурации не работает простая маршрутизация на всем сайте

1 ответ 1

1

Вот пример моего рабочего конфига:

    'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            '' => 'site/index',

            'GET v0/<controller:\w+>/<id:\w+>.<_format>' => 'v0/<controller>/view',
            'GET v0/<controller:\w+>.<_format>' => 'v0/<controller>/index',

            'v1/<controller:[\w\-]+>/<id:[\w\d\-]+>.<_format>' => 'v1/<controller>/view',
            'v1/<controller:[\w\-]+>.<_format>' => 'v1/<controller>/index',
        ],
    ],

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.