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


PHP DropdownField::saveInto方法代码示例

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


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

示例1: saveInto

 /**
  * Save the current value of this field into a DataObject.
  * If the field it is saving to is a has_many or many_many relationship,
  * it is saved by setByIDList(), otherwise it creates a comma separated
  * list for a standard DB text/varchar field.
  *
  * @param DataObject $record The record to save into
  */
 public function saveInto(DataObjectInterface $record)
 {
     if ($this->multiple) {
         $fieldname = $this->name;
         $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
         if ($fieldname && $record && $relation && $relation instanceof RelationList) {
             $idList = is_array($this->value) ? array_values($this->value) : array();
             if (!$record->ID) {
                 $record->write();
                 // record needs to have an ID in order to set relationships
                 $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
             }
             $relation->setByIDList($idList);
         } elseif ($fieldname && $record) {
             if ($this->value) {
                 $this->value = str_replace(',', '{comma}', $this->value);
                 $record->{$fieldname} = implode(",", $this->value);
             } else {
                 $record->{$fieldname} = null;
             }
         }
     } else {
         parent::saveInto($record);
     }
 }
开发者ID:normann,项目名称:sapphire,代码行数:33,代码来源:ListboxField.php

示例2: saveInto

 /**
  * {@inheritdoc}
  */
 public function saveInto(DataObjectInterface $record)
 {
     parent::saveInto($record);
     $name = $this->getName();
     $record->{$name} = join(',', $this->Value());
     $record->write();
 }
开发者ID:mediabeastnz,项目名称:silverstripe-tagfield,代码行数:10,代码来源:StringTagField.php

示例3: saveInto

 /**
  * {@inheritdoc}
  */
 public function saveInto(DataObjectInterface $record)
 {
     parent::saveInto($record);
     $name = $this->getName();
     $titleField = $this->getTitleField();
     $source = $this->getSource();
     $dataClass = $source->dataClass();
     $values = $this->Value();
     if (!$values) {
         $values = array();
     }
     if (empty($record) || empty($source) || empty($titleField)) {
         return;
     }
     if (!$record->hasMethod($name)) {
         throw new Exception(sprintf("%s does not have a %s method", get_class($record), $name));
     }
     $relation = $record->{$name}();
     foreach ($values as $i => $value) {
         if (!is_numeric($value)) {
             if (!$this->getCanCreate()) {
                 unset($values[$i]);
                 continue;
             }
             $record = new $dataClass();
             $record->{$titleField} = $value;
             $record->write();
             $values[$i] = $record->ID;
         }
     }
     if ($values instanceof SS_List) {
         $values = iterator_to_array($values);
     }
     $relation->setByIDList(array_filter($values));
 }
开发者ID:salted-herring,项目名称:silverstripe-tagfield,代码行数:38,代码来源:TagField.php

示例4: saveInto

 /**
  * {@inheritdoc}
  */
 public function saveInto(DataObjectInterface $record)
 {
     parent::saveInto($record);
     $name = $this->getName();
     $titleField = $this->getTitleField();
     $source = $this->getSource();
     $values = $this->Value();
     $relation = $record->{$name}();
     $ids = array();
     if (!$values) {
         $values = array();
     }
     if (empty($record) || empty($source) || empty($titleField)) {
         return;
     }
     if (!$record->hasMethod($name)) {
         throw new Exception(sprintf("%s does not have a %s method", get_class($record), $name));
     }
     foreach ($values as $key => $value) {
         // Get or create record
         $record = $this->getOrCreateTag($value);
         if ($record) {
             $ids[] = $record->ID;
             $values[$key] = $record->Title;
         }
     }
     $relation->setByIDList(array_filter($ids));
 }
开发者ID:mediabeastnz,项目名称:silverstripe-tagfield,代码行数:31,代码来源:TagField.php


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