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


PHP Model::saveField方法代码示例

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


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

示例1: changeStatus

 public function changeStatus(Model $Model, $status, $id = null, $force = false)
 {
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $force = true;
     $Model->id = $id;
     if (!$Model->exists()) {
         throw new NotFoundException();
     }
     if ($force !== true) {
         $modelData = $Model->read();
         if ($modelData[$Model->alias]['status'] === $status) {
             CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
             return false;
         }
     } else {
         CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     }
     $Model->saveField('status', $status);
     CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     $eventData = array();
     $eventData[Inflector::underscore($Model->name)]['id'] = $id;
     $eventData[Inflector::underscore($Model->name)]['status'] = $status;
     $overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData);
     $specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData);
     CakeEventManager::instance()->dispatch($overallEvent);
     CakeEventManager::instance()->dispatch($specificEvent);
     return true;
 }
开发者ID:cvo-technologies,项目名称:croogo-webshop-plugin,代码行数:33,代码来源:StatusBehavior.php

示例2: fixOrder

 public function fixOrder(Model $model, $conditions)
 {
     $count = $model->find('count', array('conditions' => $conditions));
     if ($count > 0) {
         $list = $model->find('list', array('conditions' => $conditions, 'order' => array($model->alias . '.order')));
         $order = 1;
         foreach ($list as $id => $name) {
             $model->id = $id;
             $model->saveField('order', $order++);
         }
     }
 }
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:12,代码来源:ReorderBehavior.php

示例3: afterSave

 public function afterSave(Model $Model, $created, $options = array())
 {
     $isTree = in_array('Tree', array_map('strtolower', $Model->Behaviors->attached()));
     if ($Model->brwConfig['sortable'] and $created and !$isTree) {
         $data = $Model->data;
         $Model->saveField($Model->brwConfig['sortable']['field'], $Model->id);
         $Model->data = $data;
     }
     if ($isTree) {
         $Model->recover();
     }
 }
开发者ID:maniekx1984,项目名称:new_va_dev_copy_GITHUB,代码行数:12,代码来源:BrwPanelBehavior.php

示例4: afterSave

 /**
  * afterSave callback
  *
  * @param Model $Model Model using this behavior
  * @param boolean $created True if this save created a new record
  * @return void
  */
 public function afterSave(Model $Model, $created)
 {
     if ($created) {
         $default = $Model->getDefaultRole();
         $role_id = $default[$this->roleModel]['id'];
         $Model->saveField('role_id', $role_id);
         $this->syncAclRole($Model, array('model' => $this->roleModel, 'foreign_key' => $role_id));
     } else {
         $new_role = array('model' => $this->roleModel, 'foreign_key' => $Model->field('role_id'));
         $this->syncAclRole($Model, $new_role, $this->oldRole[$Model->alias]);
     }
     return true;
 }
开发者ID:sanyaade-machine-learning,项目名称:Catool,代码行数:20,代码来源:RBACLBehavior.php

示例5: afterSave

 public function afterSave(Model $model, $created, $options = array())
 {
     if (!empty($model->data[$model->name]['thumb']['name'])) {
         $file = $model->data[$model->name]['thumb'];
         // Current thumb
         $media_id = $model->field('media_id');
         if ($media_id != 0) {
             $model->Media->delete($media_id);
         }
         // Update thumb
         $model->Media->save(array('ref_id' => $model->id, 'ref' => $model->name, 'file' => $file));
         $model->saveField('media_id', $model->Media->id);
     }
 }
开发者ID:smagic39,项目名称:CakePHP-Media,代码行数:14,代码来源:MediaBehavior.php

示例6: deactivate

 /**
  * @param Model $Model
  * @param       $id
  *
  * @return bool
  */
 public function deactivate(Model $Model, $id)
 {
     if (empty($id)) {
         return false;
     }
     $Model->id = $id;
     if (!$Model->exists()) {
         return false;
     }
     if ($Model->saveField('active', false)) {
         return true;
     }
     return false;
 }
开发者ID:andtxr,项目名称:cakephp-control,代码行数:20,代码来源:ControlBehavior.php

示例7: increment

 public function increment(Model $Model, $id = null, $field = null)
 {
     if (!$field && key($this->settings[$Model->alias]['fields'])) {
         $field = key($this->settings[$Model->alias]['fields']);
     }
     if (!$field) {
         return false;
     }
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $Model->id = $id;
     $currentValue = $Model->field($field, array($Model->alias . '.id' => $id));
     $result = $Model->saveField($field, $currentValue + 1);
     if (!$result) {
         return false;
     }
     return $currentValue + 1;
 }
开发者ID:cvo-technologies,项目名称:croogo-webshop-plugin,代码行数:22,代码来源:CounterBehavior.php

示例8: afterSave

 /**
  * Save each file to folder and update db
  *
  * @param Model $Model
  * @param boolean $created
  */
 public function afterSave(Model $Model, $created)
 {
     if ($this->_saving) {
         return true;
     }
     $this->_saving = true;
     if (!empty($this->_uploadLater)) {
         foreach ($this->_uploadLater as $key => $fields) {
             foreach ($fields as $name => $file) {
                 if (!is_uploaded_file($file['tmp_name'])) {
                     continue;
                 }
                 $ext = strtolower(strrchr($file['name'], '.'));
                 $filename = md5($file['name'] . $file['size']) . $ext;
                 $dest = $this->settings['uploadLocation'] . Inflector::tableize($Model->alias) . DS;
                 if (!file_exists($dest)) {
                     new Folder($dest, true);
                 }
                 move_uploaded_file($file['tmp_name'], $dest . $filename);
                 $Model->saveField($name, $filename);
             }
         }
         $this->_uploadLater = array();
     }
     $this->_saving = false;
     $Model->data = $Model->findById($Model->id);
     return true;
 }
开发者ID:shama,项目名称:oven,代码行数:34,代码来源:UploadBehavior.php

示例9: afterSave

 /**
  * Updates the model's state when a $model->save() call is performed
  * 
  * @param	Model	$model		The model being acted on
  * @param	boolean $created	Whether or not the model was created
  * @param	array	$options	Options passed to save
  * @return	boolean
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if ($created) {
         $model->read();
         $model->saveField('state', $model->initialState);
     }
     return true;
 }
开发者ID:davidsteinsland,项目名称:cakephp-state-machine,代码行数:16,代码来源:StateMachineBehavior.php

示例10: array

 /**
  * Gets the current schema version from the DB. If schema_info doesn't exist - it tries to create it.
  *
  * @access protected
  * @return int Current schema version
  */
 function _getMigrationVersion()
 {
     //load tables and see if schema_info already exists. If not, create it
     $sTables = $this->oMigrations->oDb->listSources();
     if (!in_array($this->oMigrations->oDb->config['prefix'] . 'schema_info', $sTables)) {
         $this->oMigrations->oDb->query($this->oMigrations->create_table('schema_info', array(0 => 'no_id', 1 => 'no_dates', 'version' => array('type' => 'int', 'length' => 3, 'default' => '0'))));
         //feed it with some data
         App::import('model');
         $oTemp_model = new Model(false, 'schema_info');
         $oTemp_model->saveField('version', '0');
         $this->iCurrent_version = 0;
     } else {
         App::import('model');
         $oTemp_model = new Model(false, 'schema_info');
         $this->iCurrent_version = $oTemp_model->field('version');
     }
 }
开发者ID:jmhobbs,项目名称:cakephp-yaml-migrations-and-fixtures,代码行数:23,代码来源:migrate.php

示例11: afterSave

 public function afterSave(Model $model, $created, $options = array())
 {
     $allowed = true;
     if (empty($model->data)) {
         $model->data = $model->read();
     }
     if (!empty($this->settings[$model->alias]['scope'])) {
         foreach ($this->settings[$model->alias]['scope'] as $field => $value) {
             if ($model->data[$model->alias][$field] != $value) {
                 $allowed = false;
             }
         }
     }
     if (!$this->settings[$model->alias]['calendarId']) {
         $allowed = false;
     }
     if (empty($model->data[$model->alias]['title'])) {
         $allowed = false;
     }
     $startTime = false;
     $endTime = false;
     if ($allowed && !empty($model->data[$model->alias]['date'])) {
         $startDate = strtotime($model->data[$model->alias]['date']);
         $startDate = date('Y-m-d', $startDate);
         if (!empty($model->data[$model->alias]['date_to'])) {
             $endDate = strtotime($model->data[$model->alias]['date_to']) + 24 * 3600;
             $endDate = date('Y-m-d', $endDate);
         } else {
             $endDate = strtotime($model->data[$model->alias]['date']) + 24 * 3600;
             $endDate = date('Y-m-d', $endDate);
         }
     }
     if ($allowed && !empty($model->data[$model->alias]['days'])) {
         date_default_timezone_set('UTC');
         $until = gmdate("Ymd\\THis\\Z", strtotime($model->data[$model->alias]['date_to']));
         $byDay = implode(',', $model->data[$model->alias]['days']);
         $recurrence = array(sprintf('RRULE:FREQ=WEEKLY;UNTIL=%s;BYDAY=%s', $until, $byDay));
         $endDate = $startDate;
     }
     if (empty($startDate) || empty($endDate)) {
         $allowed = false;
     }
     if ($allowed) {
         $calendarId = $this->settings[$model->alias]['calendarId'];
         $data = array('summary' => $model->data[$model->alias]['title'], 'start' => array('date' => $startDate), 'end' => array('date' => $endDate));
         if (!empty($recurrence)) {
             $data['recurrence'] = $recurrence;
         }
         if (!empty($model->data[$model->alias]['content'])) {
             $description = $model->data[$model->alias]['content'];
             $description = str_replace('<br />', PHP_EOL, $description);
             $description = strip_tags($description);
             $data['description'] = $description;
         }
         if (!empty($model->data[$model->alias]['location'])) {
             $location = $model->data[$model->alias]['location'];
             $location = strip_tags($location);
             $data['location'] = $location;
         }
         if (!empty($model->data[$model->alias]['color_id'])) {
             $data['colorId'] = $model->data[$model->alias]['color_id'];
         }
         $Events = ClassRegistry::init('Google.GoogleCalendarEvents');
         if (empty($model->data[$model->alias]['google_event_id'])) {
             $saved = $Events->insert($calendarId, $data);
             $model->id = $model->data[$model->alias]['id'];
             return $model->saveField('google_event_id', $saved['id']);
         } else {
             $eventId = $model->data['Event']['google_event_id'];
             $data['sequence'] = $model->data['Event']['google_event_sequence'] + 1;
             $saved = $Events->update($calendarId, $eventId, $data);
             if ($saved) {
                 $model->id = $model->data[$model->alias]['id'];
                 $model->Behaviors->disable('GoogleCalendarEvent');
                 return $model->saveField('google_event_sequence', $data['sequence']);
             }
         }
     } else {
         if (!$allowed && !empty($model->data[$model->alias]['google_event_id'])) {
             $deleteAllowed = true;
             if (!$this->settings[$model->alias]['calendarId']) {
                 $deleteAllowed = false;
             }
             if (empty($model->data[$model->alias]['google_event_id'])) {
                 $deleteAllowed = false;
             }
             if ($deleteAllowed) {
                 $Events = ClassRegistry::init('Google.GoogleCalendarEvents');
                 $calendarId = $this->settings[$model->alias]['calendarId'];
                 $eventId = $model->data[$model->alias]['google_event_id'];
                 $Events->delete($calendarId, $eventId);
             }
         }
     }
     return true;
 }
开发者ID:kaburk,项目名称:CakePHP-Google,代码行数:96,代码来源:GoogleCalendarEventBehavior.php

示例12: saveField

 public function saveField($name, $value, $validate = false)
 {
     $this->useMasterDb();
     return parent::saveField($name, $value, $validate);
 }
开发者ID:nano-eight,项目名称:MysqlUtil,代码行数:5,代码来源:ReplicationBaseModel.php

示例13: fieldToggle

 /**
  * Toggle field status
  *
  * @param $model Model instance
  * @param $id integer Model id
  * @param $status integer current status
  * @param $field string field name to toggle
  * @throws CakeException
  */
 public function fieldToggle(Model $model, $id, $status, $field = 'status')
 {
     if (empty($id) || $status === null) {
         throw new CakeException(__d('croogo', 'Invalid content'));
     }
     $model->id = $id;
     $status = (int) (!$status);
     $this->_controller->layout = 'ajax';
     if ($model->saveField($field, $status)) {
         $this->_controller->set(compact('id', 'status'));
         $this->_controller->render('Common/admin_toggle');
     } else {
         throw new CakeException(__d('croogo', 'Failed toggling field %s to %s', $field, $status));
     }
 }
开发者ID:ahmadhasankhan,项目名称:croogo,代码行数:24,代码来源:CroogoComponent.php

示例14: unDelete

 /**
  * Método para "desdeletar" uma entrada do modelo.
  *
  * @param Model $Model
  * @param int $id
  */
 public function unDelete(&$Model, $id)
 {
     $Model->id = $id;
     return $Model->saveField($this->settings[$Model->alias]['field'], false) !== false;
 }
开发者ID:radig,项目名称:SoftDelete,代码行数:11,代码来源:SoftDeleteBehavior.php

示例15: _moveUpDown

 /**
  * @param Model $Model
  * @param string $direction
  * @param int $steps Steps to jump. Defaults to 1.
  * @return bool Success
  */
 protected function _moveUpDown(Model $Model, $direction, $id, $steps = 1)
 {
     // FIXME: Sort over more than one placement.
     if ($direction === 'down' && empty($this->settings[$Model->alias]['reverse'])) {
         $order = '<=';
         $findOrder = 'DESC';
     } else {
         $order = '>=';
         $findOrder = 'ASC';
     }
     $sort = $Model->find('list', array('fields' => array($this->settings[$Model->alias]['field']), 'conditions' => array('id' => $id)));
     if (empty($sort)) {
         return false;
     }
     list($sort) = array_values($sort);
     $data = $Model->find('list', array('fields' => array('id', $this->settings[$Model->alias]['field']), 'conditions' => array($this->settings[$Model->alias]['field'] . ' ' . $order => $sort), 'order' => array($this->settings[$Model->alias]['field'] => $findOrder), 'limit' => $steps + 1));
     $value = end($data);
     $key = key($data);
     if ($key == $id) {
         return;
     }
     $lastId = $Model->id;
     if ($sort == $value) {
         if ($direction === 'down' && empty($this->settings[$Model->alias]['reverse'])) {
             $value++;
         } else {
             $value--;
         }
     }
     $Model->id = $key;
     $Model->saveField($this->settings[$Model->alias]['field'], $sort);
     $Model->id = $id;
     $Model->saveField($this->settings[$Model->alias]['field'], $value);
     $Model->id = $lastId;
     return true;
 }
开发者ID:Jony01,项目名称:LLD,代码行数:42,代码来源:SortableBehavior.php


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