gpt4 book ai didi

symfony - symfony2 中的货币列表

转载 作者:行者123 更新时间:2023-12-02 15:46:52 25 4
gpt4 key购买 nike

我记得在 symfony 1.x 中有一个“货币”字段类型,它是世界上所有货币的选择。 symfony2中有类似的东西吗?

最佳答案

我找不到,所以我自己创建了一个。我从 here 获取了列表

这是一个包含所有货币的类

namespace Gilden\Bundle\InvoiceBundle\Form\Extension\ChoiceList;

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;

/**
* Choice list for ISO currencies found on http://www.xe.com/iso4217.php
*/
class CurrencyChoiceList implements ChoiceListInterface
{
public function getChoices()
{
return array(
'AED' => 'AED', 'AFN' => 'AFN', 'ALL' => 'ALL',
'AMD' => 'AMD', 'ANG' => 'ANG', 'AOA' => 'AOA',
'ARS' => 'ARS', 'AUD' => 'AUD', 'AWG' => 'AWG',
'AZN' => 'AZN', 'BAM' => 'BAM', 'BBD' => 'BBD',
'BDT' => 'BDT', 'BGN' => 'BGN', 'BHD' => 'BHD',
'BIF' => 'BIF', 'BMD' => 'BMD', 'BND' => 'BND',
'BOB' => 'BOB', 'BRL' => 'BRL', 'BSD' => 'BSD',
'BTN' => 'BTN', 'BWP' => 'BWP', 'BYR' => 'BYR',
'BZD' => 'BZD', 'CAD' => 'CAD', 'CDF' => 'CDF',
'CHF' => 'CHF', 'CLP' => 'CLP', 'CNY' => 'CNY',
'COP' => 'COP', 'CRC' => 'CRC', 'CUC' => 'CUC',
'CUP' => 'CUP', 'CVE' => 'CVE', 'CZK' => 'CZK',
'DJF' => 'DJF', 'DKK' => 'DKK', 'DOP' => 'DOP',
'DZD' => 'DZD', 'EGP' => 'EGP', 'ERN' => 'ERN',
'ETB' => 'ETB', 'EUR' => 'EUR', 'FJD' => 'FJD',
'FKP' => 'FKP', 'GBP' => 'GBP', 'GEL' => 'GEL',
'GGP' => 'GGP', 'GHS' => 'GHS', 'GIP' => 'GIP',
'GMD' => 'GMD', 'GNF' => 'GNF', 'GTQ' => 'GTQ',
'GYD' => 'GYD', 'HKD' => 'HKD', 'HNL' => 'HNL',
'HRK' => 'HRK', 'HTG' => 'HTG', 'HUF' => 'HUF',
'IDR' => 'IDR', 'ILS' => 'ILS', 'IMP' => 'IMP',
'INR' => 'INR', 'IQD' => 'IQD', 'IRR' => 'IRR',
'ISK' => 'ISK', 'JEP' => 'JEP', 'JMD' => 'JMD',
'JOD' => 'JOD', 'JPY' => 'JPY', 'KES' => 'KES',
'KGS' => 'KGS', 'KHR' => 'KHR', 'KMF' => 'KMF',
'KPW' => 'KPW', 'KRW' => 'KRW', 'KWD' => 'KWD',
'KYD' => 'KYD', 'KZT' => 'KZT', 'LAK' => 'LAK',
'LBP' => 'LBP', 'LKR' => 'LKR', 'LRD' => 'LRD',
'LSL' => 'LSL', 'LTL' => 'LTL', 'LVL' => 'LVL',
'LYD' => 'LYD', 'MAD' => 'MAD', 'MDL' => 'MDL',
'MGA' => 'MGA', 'MKD' => 'MKD', 'MMK' => 'MMK',
'MNT' => 'MNT', 'MOP' => 'MOP', 'MRO' => 'MRO',
'MUR' => 'MUR', 'MVR' => 'MVR', 'MWK' => 'MWK',
'MXN' => 'MXN', 'MYR' => 'MYR', 'MZN' => 'MZN',
'NAD' => 'NAD', 'NGN' => 'NGN', 'NIO' => 'NIO',
'NOK' => 'NOK', 'NPR' => 'NPR', 'NZD' => 'NZD',
'OMR' => 'OMR', 'PAB' => 'PAB', 'PEN' => 'PEN',
'PGK' => 'PGK', 'PHP' => 'PHP', 'PKR' => 'PKR',
'PLN' => 'PLN', 'PYG' => 'PYG', 'QAR' => 'QAR',
'RON' => 'RON', 'RSD' => 'RSD', 'RUB' => 'RUB',
'RWF' => 'RWF', 'SAR' => 'SAR', 'SBD' => 'SBD',
'SCR' => 'SCR', 'SDG' => 'SDG', 'SEK' => 'SEK',
'SGD' => 'SGD', 'SHP' => 'SHP', 'SLL' => 'SLL',
'SOS' => 'SOS', 'SPL' => 'SPL', 'SRD' => 'SRD',
'STD' => 'STD', 'SVC' => 'SVC', 'SYP' => 'SYP',
'SZL' => 'SZL', 'THB' => 'THB', 'TJS' => 'TJS',
'TMT' => 'TMT', 'TND' => 'TND', 'TOP' => 'TOP',
'TRY' => 'TRY', 'TTD' => 'TTD', 'TVD' => 'TVD',
'TWD' => 'TWD', 'TZS' => 'TZS', 'UAH' => 'UAH',
'UGX' => 'UGX', 'USD' => 'USD', 'UYU' => 'UYU',
'UZS' => 'UZS', 'VEF' => 'VEF', 'VND' => 'VND',
'VUV' => 'VUV', 'WST' => 'WST', 'XAF' => 'XAF',
'XCD' => 'XCD', 'XDR' => 'XDR', 'XOF' => 'XOF',
'XPF' => 'XPF', 'YER' => 'YER', 'ZAR' => 'ZAR',
'ZMK' => 'ZMK', 'ZWD' => 'ZWD',
);
}
}

这是实际的表单类型

namespace Gilden\Bundle\InvoiceBundle\Form\Extension\Type;

use Gilden\Bundle\InvoiceBundle\Form\Extension\ChoiceList\CurrencyChoiceList;
use Symfony\Component\Form\AbstractType;

class CurrencyType extends AbstractType
{
/**
* {@inheritDoc}
*/
public function getDefaultOptions(array $options)
{
return array(
'choice_list' => new CurrencyChoiceList(),
'preferred_choices' => array('EUR', 'USD', 'RUB', 'LVL', 'LTL')
);
}

/**
* {@inheritDoc}
*/
public function getParent(array $options)
{
return 'choice';
}

/**
* {@inheritDoc}
*/
public function getName()
{
return 'currency';
}
}

我希望这会有所帮助。

关于symfony - symfony2 中的货币列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8860079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com