I am working with Symfony 2.6 and the application has an icons
directory inside web
directly. In icons
directory user uploads set of icons. I need to display names of those icons in a dropdown menu on a form that the twig
will display
I know how to
All I need is to assign the set of icons to an array so I can pass that to twig
I am working with Symfony Finder component use Symfony\\Component\\Finder\\Finder;
and I can get the results I need using the following code in a controller
$finder = new Finder();
$finder->in($this->container->getParameter('icons_path'));
$finder->sortByName();
foreach ($finder as $file) {
print pathinfo($file->getRelativePathname(), PATHINFO_FILENAME)."<br>";
}
The above code gives me an output that looks like this
As you can see it is not an array. I will really appreciate if I can get some assistance on how to make this an array.
Sometimes small little things makes you go crazy This is how i did it
$icons[] = pathinfo($file->getRelativePathname(), PATHINFO_FILENAME);
This is what complete foreach looks like
foreach ($finder as $file) {
$icons[] = pathinfo($file->getRelativePathname(), PATHINFO_FILENAME);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.