我有一个服务类:
namespace App\DesktopBundle\Lib;
class MediaManager
{
// media image path
protected $media_url;
/**
* Constructor of class
* @param $media_url
*/
public function __construct($media_url)
{
$this->image_url = $media_url;
}
public function getImage($media_type, $url){
return sprintf("%s/%s/%s", $this->image_url, $media_type, $url);
}
}
在/src/App/DesktopBundle/Resources/config/services.yml
我有:
services:
media_manager:
class: App\DesktopBundle\Lib\MediaManager
arguments: [%media_url%, "media_type","url"]
在/app/config/config.yml
我有:
twig:
globals:
mediaService: "@media_manager"
在模板中我尝试:
<img src="{{ asset(mediaService.getImage('gifts','150x150')) }}" alt="team member img">
但我有错误:Variable "mediaService" does not exist in
。你能帮我吗?提前谢谢。