在symfony 2中如何访问php中的twig模板基本url参数?

How do I access base url in service or any other class ?

framework:
    templating:
        engines: ['twig']
        packages:
            assets:
                base_urls: ["http://assets.acme.com"] 

I suppose your code is in app/config/config/yml

Look, this code is in my controller :

use Symfony\Component\Yaml\Yaml;
[...]

$configfile = Yaml::parse($this->get('kernel')->getRootDir().'/config/config.yml');
baseurls = $configfile['framework']['templating']['packages']['assets']['base_urls']);

You have to mention base_url into parameter section like

parameters:
base_urls: http://assets.acme.com

and then with the help of container object you can access into any services or class.

like in Controllar use

$this->container->getParameter('base_urls');

Generally:

$assetUrl = $this->container->get('templating.helper.assets')->getUrl($path, $packageName);

In your case:

$baseUrl = $this->container->get('templating.helper.assets')->getUrl('', 'assets');