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


PHP DataGenerator::generateParents方法代码示例

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


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

示例1: generate

 /**
  * Generate records (populate them with either prepared or default values) and insert into database.
  * This method could create parent records (we call "parent" all records in tables where generated
  * record has foreign keys linked to).
  *
  * Returns array ids of created records.
  *
  * Examples:
  *
  * // Lazy generate 7 records
  * $aMytableIds = DataGenerator::generate('mytable', 7);
  *
  * // Create dataobject and pass it into generator
  * $doMyTable = OA_Dal::factoryDO('mytable');
  * $doMyTable->column1 = 'some value';
  * $aMytableIds = DataGenerator::generate($doMyTable, 7);
  *
  * @see DB_DataObject::insert()
  * @param mixed $do              Either DataObject or table name (as string)
  * @param int $numberOfCopies    How many records should be generated
  * @param bool $generateParents  Should parent records be generated?
  * @return array                 Array ids of created records
  * @access public
  * @static
  */
 function generate($do, $numberOfCopies = 1, $generateParents = false)
 {
     // Cleanup ancestor ids
     DataGenerator::getReferenceId();
     if (is_string($do)) {
         // Lazy DataObject initialization
         $do = OA_Dal::factoryDO($do);
         if (PEAR::isError($do)) {
             return array();
         }
     }
     if ($generateParents) {
         if (!empty($this) && is_a($this, 'DataGenerator')) {
             $this->generateParents($do);
         } else {
             DataGenerator::generateParents($do);
         }
     }
     $doOriginal = clone $do;
     if (isset($this) && is_a($this, 'DataGenerator')) {
         $this->setDefaultValues($do);
     } else {
         DataGenerator::setDefaultValues($do);
     }
     DataGenerator::trackData($do->getTableWithoutPrefix());
     $ids = array();
     for ($i = 0; $i < $numberOfCopies; $i++) {
         $id = $do->insert();
         $do = clone $doOriginal;
         if (!empty($this) && is_a($this, 'DataGenerator')) {
             $this->setDefaultValues($do, $i + 1);
         } else {
             DataGenerator::setDefaultValues($do, $i + 1);
         }
         $ids[] = $id;
     }
     return $ids;
 }
开发者ID:villos,项目名称:tree_admin,代码行数:63,代码来源:DataGenerator.php


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