當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UploadField::setValue方法代碼示例

本文整理匯總了PHP中UploadField::setValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP UploadField::setValue方法的具體用法?PHP UploadField::setValue怎麽用?PHP UploadField::setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UploadField的用法示例。


在下文中一共展示了UploadField::setValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setValue

 public function setValue($value, $record = null)
 {
     $items = new ArrayList();
     // Determine format of presented data
     if (empty($value) && $record) {
         // If a record is given as a second parameter, but no submitted values,
         // then we should inspect this instead for the form values
         if ($record instanceof DataObject && $record->hasMethod($this->getFieldName())) {
             // If given a dataobject use reflection to extract details
             $data = $record->{$this->getFieldName()}();
             if ($data instanceof DataObject) {
                 // If has_one, add sole item to default list
                 $items->push($data);
             } elseif ($data instanceof SS_List) {
                 // For many_many and has_many relations we can use the relation list directly
                 $items = $data;
             }
         } elseif ($record instanceof SS_List) {
             // If directly passing a list then save the items directly
             $items = $record;
         }
     } elseif (!empty($value['Files'])) {
         // If value is given as an array (such as a posted form), extract File IDs from this
         $class = $this->getRelationAutosetClass();
         $items = DataObject::get($class)->byIDs($value['Files']);
     }
     // If javascript is disabled, direct file upload (non-html5 style) can
     // trigger a single or multiple file submission. Note that this may be
     // included in addition to re-submitted File IDs as above, so these
     // should be added to the list instead of operated on independently.
     if ($uploadedFiles = $this->extractUploadedFileData($value)) {
         foreach ($uploadedFiles as $tempFile) {
             $file = $this->saveTemporaryFile($tempFile, $error);
             if ($file) {
                 $items->add($file);
             } else {
                 throw new ValidationException($error);
             }
         }
     }
     // Filter items by what's allowed to be viewed
     $filteredItems = new ArrayList();
     $fileIDs = array();
     foreach ($items as $file) {
         if ($file->exists() && $file->canView()) {
             $filteredItems->push($file);
             $fileIDs[] = $file->ID;
         }
     }
     // Filter and cache updated item list
     $this->items = $filteredItems;
     // Same format as posted form values for this field. Also ensures that
     // $this->setValue($this->getValue()); is non-destructive
     $value = $fileIDs ? array('Files' => $fileIDs) : null;
     // Set value using parent
     return parent::setValue($value, $record);
 }
開發者ID:webtorque7,項目名稱:inpage-modules,代碼行數:57,代碼來源:ContentModuleUploadField.php

示例2: setValue

 /**
  * Sets the value of the field and also of the child fields.
  * @param array $value Submitted form data.
  * @param DataObject $record The dataobject containing the record data.
  * @return UploadField self reference.
  */
 public function setValue($value, $record = null)
 {
     // Check if there is data for this object in the record, there is after the
     // form is submitted but normally not when the page is displayed for the first time.
     if (isset($record[$this->name])) {
         // Set the values for the lat and long fields to the values from the records
         // we need to do this otherwise the come saving time they will only have the default values.
         $this->latField->setValue($record[$this->name]['Latitude']);
         $this->lngField->setValue($record[$this->name]['Longitude']);
         $this->zoomField->setValue($record[$this->name]['Zoom']);
     }
     // Call parent to do the normal things including returning self reference.
     return parent::setValue($value, $record);
 }
開發者ID:zarocknz,項目名稱:silverstripe-geodata-uploadfield,代碼行數:20,代碼來源:GeodataUploadField.php


注:本文中的UploadField::setValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。