2011-08-11 87 views

回答

1

我設法解決了這個問題。你需要重寫用於連接適配器DataDict類(在我們的例子中,Doctrine_DataDict_Mysql

我註冊了一個自定義連接類

$manager = Doctrine_Manager::getInstance(); 
$manager->registerConnectionDriver('mysql', 'My_Doctrine_Connection_Mysql'); 

My_Doctrine_Connection_Mysql

class My_Doctrine_Connection_Mysql extends Doctrine_Connection_Mysql 
{ 
    /** 
    * Data Dict(ator|ionary)? 
    * @var My_Doctrine_DataDict_Mysql 
    */ 
    protected $_dataDict; 

    /** 
    * __get Overloading method 
    * @param string $name 
    * @return mixed 
    */ 
    public function __get($name) 
    { 
     if ('dataDict' === $name) { 
      if (null === $this->_dataDict) { 
       $this->_dataDict = new My_Doctrine_DataDict_Mysql($this); 
      } 

      return $this->_dataDict; 
     } 

     return parent::__get($name); 
    } 
} 

並在My_Doctrine_DataDict_Mysql

class My_Doctrine_DataDict_Mysql extends Doctrine_DataDict_Mysql 
{ 
    /** 
    * @see parent::getPortableDecleration 
    * @param array $field 
    * @return array 
    */ 
    public function getPortableDeclaration(array $field) 
    { 
     $definition = parent::getPortableDeclaration($field); 

     // Normalising field type. Pulled almost exactly from parent 
     $length = null; 
     $dbType = strtolower($field['type']); 
     $dbType = strtok($dbType, '(), '); 
     if ($dbType == 'national') { 
      $dbType = strtok('(), '); 
     } 
     if (isset($field['length'])) { 
      $length = $field['length']; 
     } else { 
      $length = strtok('(), '); 
      $decimal = strtok('(), '); 
     } 

     // Set definition 
     switch ($dbType) { 
      case 'set': 
       $definition['type'] = array('set'); 
       break; 
     } 

     return $definition; 
    } 
} 
+1

非常有用的人,謝謝。可能只是推到你的桌子上,但是哈哈,太懶了! – GordyD