C
C
chezare2016-08-29 20:18:46
Yii
chezare, 2016-08-29 20:18:46

YII2 URL manager suffixes for different formats?

I could not find how to add .json .xml suffixes to the URL manager to change the response format formats to application/json application/xml respectively

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-08-29
@webinar

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '.html',
            'rules' => [
             ['pattern'=>'/', 'route' => 'site/index', 'suffix'=>false],
             ['pattern'=>'article/<url>', 'route' => 'article/one', 'suffix'=>'.html'],
             ['pattern'=>'api', 'route' => 'api/index', 'suffix'=>'.json'],
]

C
chezare, 2016-08-29
@chezare

Unfortunately, everything is not so simple, there are two suffixes and they are different and this option is not suitable
https://github.com/yiisoft/yii2/issues/7371
something similar, but I did not find a working solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question