@elisha_langworth
You can get the public
directory path from a Symfony controller using the following steps:
1 2 3 4 5 6 7 8 9 10 |
use SymfonyComponentHttpKernelKernelInterface; ... private $kernel; public function __construct(KernelInterface $kernel) { $this->kernel = $kernel; } |
1
|
$rootDir = $this->kernel->getRootDir(); |
1
|
$publicDir = $rootDir . '/../public'; |
Now you can use the $publicDir
variable to access files in the public
directory from your controller. For example, you can create file paths or URLs to assets like CSS, JavaScript, or image files.