这是关于 Symfony 3.3 中的 Finder 组件:文档getRelativePath
说:“返回相对路径”。
有人知道相对于什么吗?
- 相对于当前文件夹?
- 相对于应用程序的根?
- 相对于我作为参数提供的任何内容
in()
?
这是关于 Symfony 3.3 中的 Finder 组件:文档getRelativePath
说:“返回相对路径”。
有人知道相对于什么吗?
in()
?看起来“相对”确实意味着“相对于提供给的路径in()
”。
一个例子:
projects
| a_sub_dir
| | foo.txt
| bar.txt
如果在上述设置中,我们执行以下代码:
$finder = (new Finder())
->files()
->in('/projects');
foreach ($finder as $file) {
var_dump([
'path' => $file->getRelativePath(),
'pathName' => $file->getRelativePathname(),
]);
}
我们将收到以下输出
array(2) {
["path"]=>
string(9) "a_sub_dir"
["pathName"]=>
string(17) "a_sub_dir/foo.txt"
}
array(2) {
["path"]=>
string(0) ""
["pathName"]=>
string(7) "bar.txt"
}
附录:当使用多个值时in()
,会在两个值中找到一个文件,它将在循环中出现两次。in()
一次使用每个值的相对路径/路径名。