मूल रूप से मैं एक मनमाना (लेकिन खाली नहीं) मेरी विन्यास में कुंजी-मान जोड़ों, billings
नोड के अंतर्गत की संख्या, कि एक को परिभाषित है देना चाहते हैं, सहयोगी सरणी।की अनुमति दे Symfony 2 बंडल अर्थ विन्यास में कुंजी-मान जोड़ों
मैं अपने Configurator.php
(का हिस्सा) में यह है:
->arrayNode('billings')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
और फिर, मेरी config.yml
में:
my_bundle:
billings:
monthly : Monthly
bimonthly : Bimonthly
हालांकि, $config
outputting:
class MyBundleExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container,
new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('my_bundle.billings', $config['billings']);
var_dump($config);
die();
}
}
। .. मुझे क्या मिलता है संख्याओं द्वारा सरणी सूचकांक, न कि एक साहचर्य एक:
'billings' =>
array (size=2)
0 => string 'Monthly' (length=7)
1 => string 'Bimonthly' (length=9)
जिज्ञासा से बाहर
(और अगर यह मदद कर सकते हैं), मैं इस सरणी इंजेक्षन कोशिश कर रहा हूँ एक सेवा पैरामीटर के रूप में (इस महान बंडल से एनोटेशन: JMSDiExtraBundle):
class BillingType extends \Symfony\Component\Form\AbstractType
{
/**
* @var array
*/
private $billingChoices;
/**
* @InjectParams({"billingChoices" = @Inject("%billings%")})
*
* @param array $billingChoices
*/
public function __construct(array $billingChoices)
{
$this->billingChoices = $billingChoices;
}
}
धन्यवाद, मैं इसे आज़माने रहा हूँ और वापस रिपोर्ट! – gremo
यदि मैं 'isRequired' से बचना चाहता हूं और शून्य के मामले में डिफ़ॉल्ट सरणी प्रदान करना चाहता हूं तो क्या होगा? –
क्या मैं सही हूं कि '-> useAttributeAsKey (' name ')' 'name' 'में विशेष अर्थ है या यह कम से कम सरणी में जोड़ा गया है? – martin