2011-06-10 5 views
0

내가 완전히 통화 작업에 젠드 aproach을 이해하지 않는 것이 매우 가능하다. 내가 원하는 무엇젠드 통화

활성 통화는 유로이며, 언어는 영어 (응용 프로그램의 로케일입니다 EN_GB)로 어디 Zend_Currency 객체를하는 것입니다. Zend_Currency가 로케일에 연결되어 있고, 영어 로케일로 Zend_Currency를 만들면 EUR을 가질 수 없습니다.

나는이

$this->currency = new Zend_Currency(array('currency' => 'EUR'), "en_GB"); 

을 시도했지만 한 내가

echo $this->currency->getSymbol(); // I get £ 

하려고 통화를 변경하는 어떤 방법이없는 경우.

답변

2

이 일 :

$this->currency = new Zend_Currency('en_GB'); 
$this->currency->setFormat(array('currency' => 'EUR', 'name' =>'EUR', 'symbol' => '€')); 
-2

이 작동하는 것 같다 : -

$currency = new Zend_Currency(); 
$currency->setFormat(array('currency' => 'EUR', 'symbol' => '€')); 

당신의 getFormat를 전달할 수 있습니다() 배열과 같은 옵션을 설정할 수 있습니다. http://framework.zend.com/manual/en/zend.currency.options.html

+0

작동하지 않습니다. $ 통화 -> getName() 저를 얻는다 미국 달러 –

+0

당신은 통화 변경에 대해 내가 대답하고 자신에 대한 최종 답변을 운동 당신을 주도 getSymbol()의 결과에 대한, 특히 질문, 그래서 나는 약간 발끈 해요 내 자신의 대답을 받아 들였다. 다행히 결국 거기에있어 :) – vascowhite

+0

당신의 대답은 작동하지 않았다. 내 것이었다. 왜 설명하지 않았습니까 –

2

내가 수익을 Zend_Currency을 확장하고 그들이 (Zend_Currency을처럼 로케일이 변경되면 ... 우리가 원하지 않는)되도록 getName()getSymbol() 방법을 덮어왔다 ' 요청할 때마다 Zend_Locale_Data의 '신선한'데이터가 필요합니다.

아래 예제 클래스에서는 Default_Model_Currency()의 인스턴스를 만들고 동일한 로캘을 유지하면서 'currency'옵션을 유효한 통화 (예 : EUR, USD 등)로 설정할 수 있습니다.

<?php 

/* 
* Currency class extends Zend_Currency with exchange 
* functionality using the Exchange_Service 
* 
* @author HF Bonnet 
*/ 
class Default_Model_Currency extends Zend_Currency 
{ 
    /* 
    * Precision to round currency values with, the 
    * default precision is 0 
    */ 
    private $_precision = 0; 




    /* 
    * Set the currency's precision 
    * 
    * @attribute int $precision 
    * @return Default_Model_Currency 
    */ 
    public function setPrecision($precision) 
    { 
     $validator = new Zend_Validator_Digits(); 
     if ($validator->isValid($precision)) 
      $this->_precision = $precision; 

     return $this; 
    } 



    /* 
    * Becouse of problems with zend_currency I've choosen 
    * to override __toString 
    */ 
    public function __toString() 
    { 
     return sprintf(
      '%s %s', 
      $this->getShortName(), 
      $this->getValue() 
     ); 
    } 



    /* 
    * Get the full name from a currency, this method is overwitten 
    * to support the changing of currency without changing the locale 
    * 
    * @param string $currency (Optional) Currency name 
    * @param string|Zend_Locale $locale 
    * @return string $name 
    */ 
    public function getName($currency = null, $locale = null) 
    { 
     return Zend_Locale_Data::getContent(
      null, 
      'nametocurrency', 
      $this->getShortName() 
     ); 
    } 



    /* 
    * Get the full name from a currency, this method is overwitten 
    * to support the changing of a locale 
    *  
    * @param string $currency (Optional) Currency name 
    * @param string|Zend_Locale $locale 
    * @return string $name 
    */ 
    public function getSymbol($currency = null, $locale = null) 
    { 
     return Zend_Locale_Data::getContent(
      null, 
      'currencysymbol', 
      $this->getShortName() 
     ); 
    } 



    /* 
    * Get the localized value from the currency 
    * 
    * @return string $value 
    */ 
    public function getLocalizedValue() 
    { 
     return Zend_Locale_Format::toNumber(
      parent::getValue(), 
      array(
       'precision' => $this->_precision, 
       'locale' => $this->getLocale() 
      ) 
     ); 
    } 



    /* 
    * Get the default valuta. First checks in the Zend_Registry 
    * for the default valuta, if not found it is fetched from the 
    * database. 
    * 
    * @return string $defaultCurrency 
    */ 
    public function getDefaultValuta() 
    { 
     $currency = Zend_Registry::get('currency'); 

     if (!isset($currency['default'])): 
      $className = Zend_Registry::get('prefix')->services . 'Registry'; 
      $currency['default'] = $className::getInstance() 
              ->getDb('currencyValuta') 
              ->getDefaultValuta() 
              ->getIso(); 
      Zend_Registry::set(
       'currency', $currency 
      ); 
     endif; 

     return $currency['default']; 
    } 



    /* 
    * Exchanges the currency using the rates found in the 
    * exchange service. 
    * 
    * @attribute string $to 
    * @return Default_Model_Currency 
    */ 
    public function exchange($to) 
    { 
     if ($to === $this->getShortName()) 
      return $this; 

     $currencyTo = new Default_Model_Currency(
      array(
       'value' => 0, 
       'currency' => $to, 
       'precision' => $this->_precision 
      ) 
     ); 

     // Set the exchange service 
     $currencyTo->setService(
      $this->getExchangeService() 
     ); 

     return $currencyTo->add($this); 
    } 



    /* 
    * Get an Default_Model_Settings instance 
    * 
    * @return Default_Model_Settings 
    */ 
    public function getExchangeService() 
    { 
     $className = Zend_Registry::get('prefix')->services . 'Exchange'; 
     return $className::getInstance(); 
    } 

}