Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

How to get project directory from Symfony 4

$
0
0

What I need is the project directory or the public directory from symfony.

use App\Kernel;

class FileReader
{
    public function __construct(
       Kernel $kernel
    )
    {
        var_dump ($kernel->getProjectDir());

    }
}

The problem is I can not inject the kernel to my class.

In this post there are several strange things for me.

First, I get this error:

Cannot autowire service "App\Utils\Lotto\FileReader": argument "$kernel" of method "__construct()" references class "App\Kernel" but no such service exists. Try changing the type-hint to one of its parents: interface "Symfony\Component\HttpKernel\HttpKernelInterface", or interface "Symfony\Component\HttpKernel\KernelInterface".

Second, I have no KernelInterface from PHPStorm autocomplete, those interface is only for HttpKernelInterface what has no getProjectDirectory method.

How can I read out the /var/www/myproject or /var/www/myproject/public/?


Viewing all articles
Browse latest Browse all 3925

Trending Articles