Symfony2: how to set the root path in a symfony CLI command

EDIT: to shorten this short: is there a way to call $ kernel-> getRootDir (); from inside the extension of the twig? Or maybe from a DI container?

ORIGINAL QUESTION:

I am trying to scale images on a server using Imagine. Everything works fine like a log, since I am not trying to start rendering through the command line: In this case, it seems that there is a wrong path - I get an error message:

[Twig_Error_Runtime]

During template rendering, an exception was selected ("File ../ web / documents / 4f59ef3f76e74_test3.jpg does not exist") in "....: detail.html.twig" on line 72.

I use a twig tag that I wrote myself:

public function thumbnail($path,$width,$maxHeight=0,$alt="",$absolute=false){ /* @var $imagine \Imagine\Gd\Imagine */ $imagine = $this->container->get('imagine'); //$box = new \Imagine\Image\Box($width, $height); /* @var $image \Imagine\Image\ImageInterface */ $image = $imagine->open("../web/".$path); ... 

I also tried this (both work when I process the template through a browser request)

 $image = $imagine->open($path); 

$ path is set to "documents / 4f59ef3f76e74_test3.jpg" "documents /" is a subdirectory of "web"

Any ideas?

+4
source share
1 answer

H-found! This returns the absolute path to the system file of the web folder:

 $webRoot = $this->container->get('kernel')->getRootDir()."/../web"; 
+10
source

Source: https://habr.com/ru/post/1400576/


All Articles