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


PHP AppModel::saveAll方法代码示例

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


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

示例1: saveAll

 function saveAll($data = null, $options = array())
 {
     $controller = Sl::getInstance()->controller;
     $isNew = !$controller->id;
     // set associated model info
     if ($controller->modelClass != 'CmsNode') {
         $data['CmsNode'] += array('model' => $controller->modelClass, 'plugin' => $controller->plugin);
     }
     // remove empty Images, Attachments from data to be saved
     if (!empty($data['CmsImage'])) {
         if (empty($data['CmsImage']['id']) && empty($data['CmsImage']['filename']['name'])) {
             unset($data['CmsImage']);
         }
     }
     if (!empty($data['CmsAttachment'])) {
         foreach ($data['CmsAttachment'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['CmsAttachment'][$i]);
             }
         }
     }
     if (!empty($data['ImageGallery'])) {
         foreach ($data['ImageGallery'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['ImageGallery'][$i]);
             }
         }
     }
     if ($isNew) {
         $data['CmsNode']['auth_user_id'] = SlAuth::user('id');
     }
     if (!empty($data['CmsNode']['model'])) {
         if (empty($options['validation']) || $options['validation'] != 'only') {
             if (!parent::saveAll($data, array('validate' => 'only', 'atomic' => true) + $options)) {
                 return false;
             }
         }
         $modelObject = ClassRegistry::init("{$data['CmsNode']['plugin']}.{$data['CmsNode']['model']}");
         if (!$modelObject->saveAll($data, $options)) {
             return false;
         }
         $data['CmsNode'] += array('foreign_key' => $modelObject->id);
     }
     $result = parent::saveAll($data, $options);
     if ($result && $isNew && $this->CmsImage->id) {
         $this->CmsImage->saveField('cms_node_id', $this->id);
     }
     return $result;
 }
开发者ID:sandulungu,项目名称:StarLight,代码行数:49,代码来源:cms_node.php

示例2: saveAll

 function saveAll($data = null, $options = array())
 {
     if (empty($data)) {
         $data = $this->data;
     }
     # Do not save an empty journal
     return empty($data['JournalDetail']) && empty($data['Journal']['notes']) ? false : parent::saveAll($data, $options);
 }
开发者ID:ha1t,项目名称:candycane,代码行数:8,代码来源:Journal.php

示例3: saveAll

 /**
  * saveAll method.
  *
  * Overrides parent's saveAll so that it can perform a transaction that performs
  * DELETEs on removed Goals.
  *
  * @param array $data
  * @param array $options
  * @return mixed
  */
 public function saveAll($data = array(), $options = array())
 {
     $dataSource = $this->getDataSource();
     // Begin the transaction
     $dataSource->begin();
     // Flag to indicate a commit
     $commit = true;
     // Check for an existing Achievement, its Goals, and Showcase rows
     if (isset($data['Achievement']['id']) && $data['Achievement']['id']) {
         // Get the POSTed Goal id's
         $in = Hash::extract($data, 'Task.{n}[ref>0].ref');
         // Get the stored Goal id's
         $achievement = $this->find('first', array('conditions' => array('Achievement.id' => $data['Achievement']['id']), 'fields' => array('Achievement.id'), 'contain' => array('Goal' => array('fields' => array('Goal.id')))));
         $stored = Hash::extract($achievement, 'Goal.{n}[id>0].id');
         // Calculate the diff between the two Sets of Goal ids
         $diff = array_diff($stored, $in);
         // DELETE the missing Goals
         if (!$this->Goal->deleteAll(array('Goal.id' => $diff), true)) {
             $commit = false;
         }
         // DELETE any Showcase rows if the Achievement is going to be private
         if ($data['Achievement']['private']) {
             if (!$this->Showcase->deleteAll(array('Showcase.achievement_id' => $data['Achievement']['id']), true)) {
                 $commit = false;
             }
         }
     }
     // Normal saveAll
     if (!($result = parent::saveAll($data, $options))) {
         $commit = false;
     }
     // End the transaction
     if ($commit) {
         $dataSource->commit();
     } else {
         $dataSource->rollback();
     }
     return $result;
 }
开发者ID:bretten,项目名称:yui,代码行数:49,代码来源:Achievement.php


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