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


PHP ModelBehavior::beforeSave方法代码示例

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


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

示例1: beforeSave

 /**
  * (non-PHPdoc)
  * @see ModelBehavior::beforeSave()
  */
 public function beforeSave(Model $Model)
 {
     // проверяем необходимость сворачивания полей в gridfs
     foreach ($this->_settings['fields'] as $field) {
         $data = $Model->data[$Model->alias];
         $paths = explode('.', $field);
         foreach ($paths as $path) {
             if (!empty($data[$path])) {
                 $data = $data[$path];
             } else {
                 $data = null;
             }
         }
         $bytes = serialize($data);
         if (!empty($data) && mb_strlen($bytes, '8bit') > $this->_settings['size']) {
             // сохраняем содержимое поля в gridfs, а в значение поля записываем id в grid-е
             $value = $this->_Grid->storeBytes($bytes);
             if (count($paths) == 1) {
                 $Model->data[$Model->alias][$paths[0]] = $value;
             } elseif (count($paths) == 2) {
                 $Model->data[$Model->alias][$paths[0]][$paths[1]] = $value;
             } elseif (count($paths) == 3) {
                 $Model->data[$Model->alias][$paths[0]][$paths[1]][$paths[2]] = $value;
             } elseif (count($paths) == 4) {
                 $Model->data[$Model->alias][$paths[0]][$paths[1]][$paths[2]][$paths[3]] = $value;
             }
         }
     }
     return parent::beforeSave($Model);
 }
开发者ID:pdedkov,项目名称:cakephp-mongo,代码行数:34,代码来源:GridFsBehavior.php

示例2: beforeSave

 /**
  * Run before a model is saved, used to set up slug for model.
  *
  * @param object $Model Model about to be saved.
  * @return boolean true if save should proceed, false otherwise
  * @access public
  */
 function beforeSave(&$Model)
 {
     $return = parent::beforeSave($Model);
     // Make label fields an array
     if (!is_array($this->__settings[$Model->alias]['label'])) {
         $this->__settings[$Model->alias]['label'] = array($this->__settings[$Model->alias]['label']);
     }
     // Make sure all label fields are available
     foreach ($this->__settings[$Model->alias]['label'] as $field) {
         if (!$Model->hasField($field)) {
             return $return;
         }
     }
     // See if we should be generating a slug
     if ($Model->hasField($this->__settings[$Model->alias]['slug']) && ($this->__settings[$Model->alias]['overwrite'] || empty($Model->id))) {
         // Build label out of data in label fields, if available, or using a default slug otherwise
         $label = '';
         foreach ($this->__settings[$Model->alias]['label'] as $field) {
             if (!empty($Model->data[$Model->alias][$field])) {
                 $label .= ife(!empty($label), ' ', '') . $Model->data[$Model->alias][$field];
             }
         }
         // Keep on going only if we've got something to slug
         if (!empty($label)) {
             // Get the slug
             $slug = $this->__slug($label, $this->__settings[$Model->alias]);
             // Look for slugs that start with the same slug we've just generated
             $conditions = array($Model->alias . '.' . $this->__settings[$Model->alias]['slug'] => 'LIKE ' . $slug . '%');
             if (!empty($Model->id)) {
                 $conditions[$Model->alias . '.' . $Model->primaryKey] = '!= ' . $Model->id;
             }
             $result = $Model->find('all', array('conditions' => $conditions, 'fields' => array($Model->primaryKey, $this->__settings[$Model->alias]['slug']), 'recursive' => -1));
             $sameUrls = null;
             if (!empty($result)) {
                 $sameUrls = Set::extract($result, '{n}.' . $Model->alias . '.' . $this->__settings[$Model->alias]['slug']);
             }
             // If we have collissions
             if (!empty($sameUrls)) {
                 $begginingSlug = $slug;
                 $index = 1;
                 // Attach an ending incremental number until we find a free slug
                 while ($index > 0) {
                     if (!in_array($begginingSlug . $this->__settings[$Model->alias]['separator'] . $index, $sameUrls)) {
                         $slug = $begginingSlug . $this->__settings[$Model->alias]['separator'] . $index;
                         $index = -1;
                     }
                     $index++;
                 }
             }
             // Now set the slug as part of the model data to be saved, making sure that
             // we are on the white list of fields to be saved
             if (!empty($Model->whitelist) && !in_array($this->__settings[$Model->alias]['slug'], $Model->whitelist)) {
                 $Model->whitelist[] = $this->__settings[$Model->alias]['slug'];
             }
             $Model->data[$Model->alias][$this->__settings[$Model->alias]['slug']] = $slug;
         }
     }
     return $return;
 }
开发者ID:rchavik,项目名称:infinitas,代码行数:66,代码来源:sluggable.php

示例3: beforeSave

 /**
  * Prepare the meta data for saving
  */
 public function beforeSave(Model $Model, $options = array())
 {
     if (isset($Model->data[$Model->alias]['MetaData'])) {
         $Model->data['MetaData'] = $Model->data[$Model->alias]['MetaData'];
         unset($Model->data[$Model->alias]['MetaData']);
     }
     return parent::beforeSave($Model, $options);
 }
开发者ID:mrstu84,项目名称:metadata,代码行数:11,代码来源:MetaBehavior.php

示例4: beforeSave

 public function beforeSave(Model $Model)
 {
     parent::beforeSave($Model);
     if ($this->settings[$Model->alias]['before'] == 'save') {
         $this->process($Model);
     }
     return true;
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:8,代码来源:TypographicBehavior.php

示例5: beforeSave

 public function beforeSave(Model $Model, $options = array())
 {
     parent::beforeSave($Model, $options);
     if ($this->settings[$Model->alias]['before'] === 'save') {
         return $this->geocode($Model);
     }
     return true;
 }
开发者ID:Jony01,项目名称:LLD,代码行数:8,代码来源:GeocoderBehavior.php

示例6: beforeSave

 public function beforeSave(Model $Model)
 {
     $return = parent::beforeSave($Model);
     if ($this->settings[$Model->alias]['before'] == 'save') {
         return $this->confirm($Model, $return);
     }
     return $return;
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:8,代码来源:MasterPasswordBehavior.php

示例7: beforeSave

 /**
  * beforeSave callback
  *
  * @param Model $model The current model being used
  * @param array $options Callback options
  *
  * @return mixed
  */
 public function beforeSave(Model $model, $options = array())
 {
     $fields = (array) $this->__settings[$model->alias]['fields'];
     $scope = (array) $this->__settings[$model->alias]['scope'];
     $conditions = !empty($this->__settings[$model->alias]['conditions']) ? (array) $this->__settings[$model->alias]['conditions'] : array();
     $slugfield = $this->__settings[$model->alias]['slugfield'];
     $hasFields = true;
     foreach ($fields as $field) {
         if (!$model->hasField($field)) {
             $hasFields = false;
         }
         if (!isset($model->data[$model->alias][$field])) {
             $hasFields = false;
         }
     }
     if ($hasFields && $model->hasField($slugfield) && ($this->__settings[$model->alias]['overwrite'] || empty($model->id))) {
         $toSlug = array();
         foreach ($fields as $field) {
             $toSlug[] = $model->data[$model->alias][$field];
         }
         $toSlug = join(' ', $toSlug);
         $slug = Inflector::slug($toSlug, $this->__settings[$model->alias]['separator']);
         if ($this->__settings[$model->alias]['lower']) {
             $slug = strtolower($slug);
         }
         if (strlen($slug) > $this->__settings[$model->alias]['length']) {
             $slug = substr($slug, 0, $this->__settings[$model->alias]['length']);
         }
         $conditions[$model->alias . '.' . $slugfield . ' LIKE'] = $slug . '%';
         if (!empty($model->id)) {
             $conditions[$model->alias . '.' . $model->primaryKey . ' !='] = $model->id;
         }
         if (!empty($scope)) {
             foreach ($scope as $s) {
                 if (isset($model->data[$model->alias][$s])) {
                     $conditions[$model->alias . '.' . $s] = $model->data[$model->alias][$s];
                 }
             }
         }
         $sameUrls = $model->find('all', array('recursive' => -1, 'conditions' => $conditions));
         $sameUrls = !empty($sameUrls) ? Hash::extract($sameUrls, '{n}.' . $model->alias . '.' . $slugfield) : array();
         if (!empty($sameUrls)) {
             if (in_array($slug, $sameUrls)) {
                 $begginingSlug = $slug;
                 $index = 1;
                 while ($index > 0) {
                     if (!in_array($begginingSlug . $this->__settings[$model->alias]['separator'] . $index, $sameUrls)) {
                         $slug = $begginingSlug . $this->__settings[$model->alias]['separator'] . $index;
                         $index = -1;
                     }
                     $index++;
                 }
             }
         }
         $model->data[$model->alias][$slugfield] = $slug;
     }
     return parent::beforeSave($model);
 }
开发者ID:eberfreitas,项目名称:cakephp-slugomatic,代码行数:66,代码来源:SlugomaticBehavior.php

示例8: beforeSave

 /**
  * beforeSave is called before a model is saved. Returning false from a beforeSave callback
  * will abort the save operation.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  *
  * @return mixed|void
  */
 public function beforeSave(\Model $model, $options = array())
 {
     parent::beforeSave($model);
     $request = new CakeRequest();
     $data = ['blog' => urlencode(Configure::read('General.site_url')), 'user_ip' => urlencode($model->data[$model->alias]['author_ip']), 'user_agent' => urlencode($model->data[$model->alias]['agent']), 'referrer' => urlencode($request->referer()), 'permalink' => urlencode($request->referer()), 'comment_type' => urlencode('comment'), 'comment_author' => urlencode($model->data[$model->alias]['author']), 'comment_author_email' => urlencode($model->data[$model->alias]['author_email']), 'comment_author_url' => urlencode($model->data[$model->alias]['author_url']), 'comment_content' => urlencode($model->data[$model->alias]['content'])];
     if (Akismet::isSpam($data, Configure::read('Akismet.api_key'))) {
         $model->data[$model->alias]['status'] = 'spam';
     }
 }
开发者ID:atkrad,项目名称:akismet,代码行数:18,代码来源:AkismetBehavior.php

示例9: beforeSave

 public function beforeSave(Model $Model, $options = array())
 {
     $return = parent::beforeSave($Model, $options);
     if ($this->settings[$Model->alias]['before'] === 'save') {
         return $this->confirm($Model, $return);
     }
     //pr($Model->data);
     return $return;
 }
开发者ID:09060906,项目名称:CakePHP-Payment-Plugin,代码行数:9,代码来源:DiscountableBehavior.php

示例10: beforeSave

 function beforeSave(Model $Model)
 {
     $data =& $Model->data[$Model->alias];
     if (!empty($data['password'])) {
         $data['salt'] = $this->generateSaltString();
         $data['password'] = $this->generateSaltedPassword($data['password'], $data['salt']);
     } else {
         unset($data['password']);
     }
     return parent::beforeSave($Model);
 }
开发者ID:voidet,项目名称:grey_tables,代码行数:11,代码来源:GreyTablesBehavior.php

示例11: beforeSave

 public function beforeSave(Model $model, $options = array())
 {
     $alias = $model->alias;
     $fields = $this->settings[$alias];
     foreach ($fields as $date => $year) {
         if (isset($model->data[$alias][$date]) && !empty($model->data[$alias][$date])) {
             $model->data[$alias][$year] = date('Y', strtotime($model->data[$alias][$date]));
         }
     }
     return parent::beforeSave($model, $options);
 }
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:11,代码来源:YearBehavior.php

示例12: beforeSave

 public function beforeSave(Model $model, $options = array())
 {
     $format = 'Y-m-d';
     $fields = $this->settings[$model->alias];
     foreach ($fields as $field) {
         if (isset($model->data[$model->alias][$field]) && !empty($model->data[$model->alias][$field])) {
             $value = $model->data[$model->alias][$field];
             $model->data[$model->alias][$field] = date($format, strtotime($value));
         }
     }
     return parent::beforeSave($model, $options);
 }
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:12,代码来源:DatePickerBehavior.php

示例13: beforeSave

 /**
  * Before save callback
  *
  * @param object $model Model using this behavior
  * @return boolean True if the operation should continue, false if it should abort
  */
 public function beforeSave($model)
 {
     $return = parent::beforeSave($model);
     if ($return === false) {
         return $return;
     }
     foreach ($this->settings[$model->alias] as $field) {
         if (isset($model->data[$model->alias][$field])) {
             $model->data[$model->alias][$field] = $this->compress($model, $model->data[$model->alias][$field]);
         }
     }
     return $return;
 }
开发者ID:rchick,项目名称:syrup,代码行数:19,代码来源:compressible.php

示例14: beforeSave

	/**
	 * Trim através do callback beforeSave
	 *
	 * @see ModelBehavior::beforeSave()
	 */
	public function beforeSave(Model $model, $options = array())
	{
		parent::beforeSave($model, $options);

		$this->_Model = $model;

		if (isset($this->_disabledFor[$model->alias])) {
			return true;
		}

		$this->_autoTrim();

		return true;
	}
开发者ID:radig,项目名称:user_guard,代码行数:19,代码来源:AutoTrimBehavior.php

示例15: beforeSave

 /**
  * Run before a model is saved, used to set up slug for model.
  *
  * @param Model $Model Model about to be saved.
  * @return boolean true if save should proceed, false otherwise
  */
 public function beforeSave(Model $Model)
 {
     $return = parent::beforeSave($Model);
     if (!is_array($this->__settings[$Model->alias]['label'])) {
         $this->__settings[$Model->alias]['label'] = array($this->__settings[$Model->alias]['label']);
     }
     foreach ($this->__settings[$Model->alias]['label'] as $field) {
         if (!$Model->hasField($field)) {
             return $return;
         }
     }
     if ($Model->hasField($this->__settings[$Model->alias]['slug']) && ($this->__settings[$Model->alias]['overwrite'] || empty($Model->id))) {
         $label = '';
         foreach ($this->__settings[$Model->alias]['label'] as $field) {
             if (!empty($Model->data[$Model->alias][$field])) {
                 $label .= (!empty($label) ? ' ' : '') . $Model->data[$Model->alias][$field];
             }
         }
         if (!empty($label)) {
             $slug = $this->__slug($label, $this->__settings[$Model->alias]);
             $conditions = array($Model->alias . '.' . $this->__settings[$Model->alias]['slug'] . ' LIKE' => $slug . '%');
             // Fix 2
             if (!empty($Model->id)) {
                 $conditions['not'] = array($Model->alias . '.' . $Model->primaryKey => $Model->id);
             }
             $result = $Model->find('all', array('conditions' => $conditions, 'fields' => array($Model->primaryKey, $this->__settings[$Model->alias]['slug']), 'recursive' => -1));
             $sameUrls = null;
             if (!empty($result)) {
                 $sameUrls = Hash::extract($result, '{n}.' . $Model->alias . '.' . $this->__settings[$Model->alias]['slug']);
             }
             if (!empty($sameUrls)) {
                 $begginingSlug = $slug;
                 $index = 1;
                 while ($index > 0) {
                     if (!in_array($begginingSlug . $this->__settings[$Model->alias]['separator'] . $index, $sameUrls)) {
                         $slug = $begginingSlug . $this->__settings[$Model->alias]['separator'] . $index;
                         $index = -1;
                     }
                     $index++;
                 }
             }
             if (!empty($Model->whitelist) && !in_array($this->__settings[$Model->alias]['slug'], $Model->whitelist)) {
                 $Model->whitelist[] = $this->__settings[$Model->alias]['slug'];
             }
             $Model->data[$Model->alias][$this->__settings[$Model->alias]['slug']] = $slug;
         }
     }
     return $return;
 }
开发者ID:tieulonglanh,项目名称:leminhhoan-01,代码行数:55,代码来源:SluggableBehavior.php


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