Note that there are some explanatory texts on larger screens.

plurals
  1. POAllowing key-value pairs in Symfony 2 Bundle semantic configuration
    primarykey
    data
    text
    <p>Basically i'd like to allow an arbitrary (but <strong>not empty</strong>) number of <strong>key-value pairs</strong> in my configuration, under <code>billings</code> node, that is define an <strong>associative array</strong>.</p> <p>I've this in my <code>Configurator.php</code> (part of):</p> <pre><code>-&gt;arrayNode('billings') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;prototype('scalar') -&gt;end() -&gt;end() </code></pre> <p>And then, in my <code>config.yml</code>:</p> <pre><code>my_bundle: billings: monthly : Monthly bimonthly : Bimonthly </code></pre> <p>However, outputting <code>$config</code>:</p> <pre><code>class MyBundleExtension extends Extension { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader-&gt;load('services.yml'); $processor = new Processor(); $configuration = new Configuration(); $config = $processor-&gt;processConfiguration($configuration, $configs); $container-&gt;setParameter('my_bundle.billings', $config['billings']); var_dump($config); die(); } } </code></pre> <p>... what i get is <strong>array index by numbers</strong>, not an associative one:</p> <pre><code> 'billings' =&gt; array (size=2) 0 =&gt; string 'Monthly' (length=7) 1 =&gt; string 'Bimonthly' (length=9) </code></pre> <p>Out of curiosity (and if this can help), i'm trying to inject this array as a service parameter (annotations from this great bundle: <a href="https://github.com/schmittjoh/JMSDiExtraBundle" rel="noreferrer">JMSDiExtraBundle</a>):</p> <pre><code>class BillingType extends \Symfony\Component\Form\AbstractType { /** * @var array */ private $billingChoices; /** * @InjectParams({"billingChoices" = @Inject("%billings%")}) * * @param array $billingChoices */ public function __construct(array $billingChoices) { $this-&gt;billingChoices = $billingChoices; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload