A
A
AlexRas2018-05-22 19:11:23
Yii
AlexRas, 2018-05-22 19:11:23

How to form a UrlManager rule with a slash?

Hello.
There is this rule:

[
  'class' => 'yii\rest\UrlRule',
  'controller' => 'file',
  'tokens' => [
    '{name}' => '<name>',
  ],
  'patterns' => [
    'GET,HEAD {name}' => 'file',
  ],
]

The url is obtained from it: http://site.ru/files/filename.jpg
Tell me how you can indicate in yii that everything after files/needs to be put into the variable {name}. You need to get this address:http://site.ru/files/folders/folder/filename.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-06-05
@kimono

It's not entirely clear what you want. Perhaps it(?):

class SiteController extends yii\web\Controller {
  public function actionFiles($name){
    if (null === $file = File::findOne(['name' = $name])){
        throw new NotFoundHttpException('File not found');
    }

    return $file->path;
  }
}

'patterns' => [
    'GET,HEAD /files/<name>' => 'site/files',
  ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question