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


PHP GridField::saveInto方法代码示例

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


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

示例1: handleReorder

 /**
  * Handles requests to reorder a set of IDs in a specific order.
  *
  * @param GridField $grid
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function handleReorder($grid, $request)
 {
     $list = $grid->getList();
     $modelClass = $grid->getModelClass();
     if ($list instanceof ManyManyList && !singleton($modelClass)->canView()) {
         $this->httpError(403);
     } else {
         if (!$list instanceof ManyManyList && !singleton($modelClass)->canEdit()) {
             $this->httpError(403);
         }
     }
     $ids = $request->postVar('order');
     $field = $this->getSortField();
     if (!is_array($ids)) {
         $this->httpError(400);
     }
     $sortterm = '';
     if ($this->extraSortFields) {
         if (is_array($this->extraSortFields)) {
             foreach ($this->extraSortFields as $col => $dir) {
                 $sortterm .= "{$col} {$dir}, ";
             }
         } else {
             $sortterm = $this->extraSortFields . ', ';
         }
     }
     $sortterm .= '"' . $this->getSortTable($list) . '"."' . $field . '"';
     $items = $list->filter('ID', $ids)->sort($sortterm);
     // Ensure that each provided ID corresponded to an actual object.
     if (count($items) != count($ids)) {
         $this->httpError(404);
     }
     // Save any un-comitted changes to the gridfield
     if (($form = $grid->getForm()) && ($record = $form->getRecord())) {
         $form->loadDataFrom($request->requestVars(), true);
         $grid->saveInto($record);
     }
     // Populate each object we are sorting with a sort value.
     $this->populateSortValues($items);
     // Generate the current sort values.
     if ($items instanceof ManyManyList) {
         $current = array();
         foreach ($items->toArray() as $record) {
             // NOTE: _SortColumn0 is the first ->sort() field
             //		 used by SS when functions are detected in a SELECT
             //	     or CASE WHEN.
             if (isset($record->_SortColumn0)) {
                 $current[$record->ID] = $record->_SortColumn0;
             } else {
                 $current[$record->ID] = $record->{$field};
             }
         }
     } else {
         $current = $items->map('ID', $field)->toArray();
     }
     // Perform the actual re-ordering.
     $this->reorderItems($list, $current, $ids);
     return $grid->FieldHolder();
 }
开发者ID:helpfulrobot,项目名称:ajshort-silverstripe-gridfieldextensions,代码行数:66,代码来源:GridFieldOrderableRows.php

示例2: handleReorder

 /**
  * Handles requests to reorder a set of IDs in a specific order.
  *
  * @param GridField $grid
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function handleReorder($grid, $request)
 {
     if (!$this->immediateUpdate) {
         $this->httpError(400);
     }
     $list = $grid->getList();
     $modelClass = $grid->getModelClass();
     if ($list instanceof ManyManyList && !singleton($modelClass)->canView()) {
         $this->httpError(403);
     } else {
         if (!$list instanceof ManyManyList && !singleton($modelClass)->canEdit()) {
             $this->httpError(403);
         }
     }
     // Save any un-committed changes to the gridfield
     if (($form = $grid->getForm()) && ($record = $form->getRecord())) {
         $form->loadDataFrom($request->requestVars(), true);
         $grid->saveInto($record);
     }
     // Get records from the `GridFieldEditableColumns` column
     $data = $request->postVar($grid->getName());
     $sortedIDs = $this->getSortedIDs($data);
     if (!$this->executeReorder($grid, $sortedIDs)) {
         $this->httpError(400);
     }
     Controller::curr()->getResponse()->addHeader('X-Status', rawurlencode('Records reordered.'));
     return $grid->FieldHolder();
 }
开发者ID:ajshort,项目名称:silverstripe-gridfieldextensions,代码行数:35,代码来源:GridFieldOrderableRows.php


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