当前位置: 首页>>代码示例>>PHP>>正文


PHP Doctrine_Lib::getRecordAsXml方法代码示例

本文整理汇总了PHP中Doctrine_Lib::getRecordAsXml方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Lib::getRecordAsXml方法的具体用法?PHP Doctrine_Lib::getRecordAsXml怎么用?PHP Doctrine_Lib::getRecordAsXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine_Lib的用法示例。


在下文中一共展示了Doctrine_Lib::getRecordAsXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRecordAsXml

 /**
  * Return a recrd as XML. 
  *
  * In order to control how this is done set the "xml" option in a record. 
  * This option is an array that has the keys "ignore_fields" and "include_relations". Both of these are arrays that list the name of fields/relations to include/process. 
  *
  * If you want to insert this xml as a part inside another xml send a 
  * SimpleXMLElement to the function. Because of the nature of SimpleXML the 
  * content you add to this element will be avilable after the function is 
  * complete.
  *
  * @param Doctrine_Record $record
  * @param SimpleXMLElement $xml
  * @return string Xml as string
  */
 public static function getRecordAsXml(Doctrine_Record $record, SimpleXMlElement $incomming_xml = NULL)
 {
     $recordname = $record->getTable()->tableName;
     if (!isset($incomming_xml)) {
         $new_xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><" . $recordname . "></" . $recordname . ">";
         $xml = new SimpleXMLElement($new_xml_string);
     } else {
         $xml = $incomming_xml->addChild($recordname);
     }
     foreach ($record->obtainIdentifier() as $pk_field => $pk_value) {
         $xml->addChild($pk_field, $pk_value);
     }
     $xml_options = $record->option("xml");
     if (isset($xml_options["record_name"])) {
         $recordname = $xml_options["record_name"];
     }
     foreach ($record->getData() as $field => $value) {
         if (isset($xml_options["ignore_fields"]) && !in_array($field, $xml_options["ignore_fields"]) || !isset($xml_options["ignore_fields"])) {
             if ($value instanceof Doctrine_Null) {
                 $xml->addChild($field);
             } else {
                 $xml->addChild($field, $value);
             }
         }
     }
     if (!isset($xml_options["include_relations"])) {
         return $xml->asXML();
     }
     $relations = $record->getTable()->getRelations();
     foreach ($relations as $name => $relation) {
         if (in_array($name, $xml_options["include_relations"])) {
             $relation_type = $relation->getType();
             $related_records = $record->get($name);
             if ($relation_type == Doctrine_Relation::ONE && $related_records instanceof Doctrine_Record) {
                 Doctrine_Lib::getRecordAsXml($related_records, $xml);
             } else {
                 Doctrine_Lib::getCollectionAsXml($related_records, $xml);
             }
         }
     }
     return $xml->asXML();
 }
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:57,代码来源:Lib.php


注:本文中的Doctrine_Lib::getRecordAsXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。