Answer the question
In order to leave comments, you need to log in
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',
],
]
http://site.ru/files/filename.jpg
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
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 questionAsk a Question
731 491 924 answers to any question