本文整理汇总了PHP中Model::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::beforeSave方法的具体用法?PHP Model::beforeSave怎么用?PHP Model::beforeSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* @author thientd
*/
public function beforeSave($options = array())
{
$result = parent::beforeSave($options);
if ($result) {
$exists = $this->exists();
$dateFields = array('modifier');
if (!$exists) {
$dateFields[] = 'creator';
}
$fields = array();
if (isset($this->data[$this->alias])) {
$fields = array_keys($this->data[$this->alias]);
}
$username = $this->__getLoginName();
foreach ($dateFields as $updateCol) {
if (in_array($updateCol, $fields) || !$this->hasField($updateCol)) {
continue;
}
if (!empty($this->whitelist)) {
$this->whitelist[] = $updateCol;
}
$this->set($updateCol, $username);
}
}
return $result;
}
示例2: beforeSave
public function beforeSave()
{
parent::beforeSave();
App::import('Controller', 'App');
$appController = new AppController();
///===> String To Slug
/// A variável transformUrl deve ser colocada na Model
if (!empty($this->transformUrl)) {
foreach ($this->transformUrl as $key => $value) {
//echo $key ." => ". $value ."<br>";
$url_amigavel = $appController->stringToSlug($this->data[$this->alias][$value]);
$this->data[$this->alias][$key] = $url_amigavel;
}
}
///===> Salvando Imagens, caso existam
if (!empty($this->type_files)) {
foreach ($this->type_files as $key => $value) {
//echo $campo ." => ". $parametros ."<br>";
if (!empty($this->data[$this->alias][$key . '_nome_imagem'])) {
$this->data[$this->alias][$key] = $this->data[$this->alias][$key . '_nome_imagem'];
$this->data[$this->alias][$key . '_th_hidden'] = $appController->thumbPath($this->data[$this->alias][$key . '_nome_imagem']);
}
}
}
return true;
}
示例3: beforeSave
/**
* standard beforeSave() callback
* Save string IPs as longs
*
* @param array $options
* @return true
*/
public function beforeSave($options = array())
{
foreach ($this->fieldsToLong as $field) {
if (isset($this->data[$this->alias][$field]) && !is_numeric($this->data[$this->alias][$field])) {
$this->data[$this->alias][$field] = ip2long($this->data[$this->alias][$field]);
}
}
return parent::beforeSave($options);
}
示例4: beforeSave
public function beforeSave($options = array())
{
parent::beforeSave($options);
$formatted = $this->formatDateFields($this->data, $this->datesToSave, "%Y-%m-%d");
if (isset($formatted[0])) {
$this->data[$this->alias] = array_replace($this->data[$this->alias], $formatted[0][$this->alias]);
}
$this->data = Sanitize::clean($this->data);
return true;
}
示例5: beforeSave
public function beforeSave()
{
/*if ($this->isNewRecord) {
//do nothing
}
else {
$this->update_time = new CDbExpression('NOW()');
}*/
$this->update_time = new CDbExpression('NOW()');
return parent::beforeSave();
}
示例6: beforeSave
public function beforeSave($options = array())
{
if (!empty($_SESSION['ProxyAuth']['realUser'])) {
//check if user is proxied for logging purposes
//need to log....
$proxyUser = $_SESSION['Auth']['User'];
$realUser = $_SESSION['ProxyAuth']['realUser'];
$logString = json_encode(array('proxyUser' => $proxyUser, 'realUser' => $realUser, 'accessedPage' => $this->name, 'requestData' => $this->data));
$this->log($logString, 'proxy');
}
return parent::beforeSave($options);
}
示例7: beforeSave
public function beforeSave($options = array())
{
parent::beforeSave($options);
$schema = $this->schema();
$class = get_class($this);
if (isset($this->data[$class])) {
$this->data[$class] = $this->addTimeToData($this->data[$class]);
}
if (isset($this->data[$class])) {
$this->data[$class] = $this->addLoggedUserToData($this->data[$class]);
}
}
示例8: beforeSave
public function beforeSave($options = array())
{
$parent = parent::beforeSave($options);
if (empty($this->data[$this->alias]['name'])) {
return $parent;
}
$name = $this->data[$this->alias]['name'];
$name_slug = strtolower(Inflector::slug($name));
$name_variable = Inflector::variable($name_slug);
$this->data[$this->alias] += compact('name_variable', 'name_slug');
return $parent;
}
示例9: beforeSave
/**
* beforeSave
*
* @return boolean
* @access public
*/
public function beforeSave($options = array())
{
$result = parent::beforeSave($options);
// 日付フィールドが空の場合、nullを保存する
foreach ($this->_schema as $key => $field) {
if (('date' == $field['type'] || 'datetime' == $field['type'] || 'time' == $field['type']) && isset($this->data[$this->name][$key])) {
if ($this->data[$this->name][$key] == '') {
$this->data[$this->name][$key] = null;
}
}
}
return $result;
}
示例10: beforeSave
public function beforeSave()
{
if ($this->isNewRecord) {
$this->create_time = new CDbExpression('NOW()');
$this->update_time = new CDbExpression('NOW()');
$this->create_by = Yii::app()->user->id;
$this->update_by = Yii::app()->user->id;
} else {
$this->update_time = new CDbExpression('NOW()');
$this->update_by = Yii::app()->user->id;
}
return parent::beforeSave();
}
示例11: beforeSave
protected function beforeSave()
{
$passwordDiffers = true;
/**
* If existing user, check password
*/
if (!$this->getIsNewRecord()) {
if (isset($this->oldAttributes['password']) && strcmp($this->oldAttributes['password'], $this->password) == 0) {
$passwordDiffers = false;
}
}
if ($passwordDiffers && !empty($this->password)) {
$this->password = $this->hashPassword($this->password);
} elseif (!empty($this->oldAttributes['password'])) {
$this->password = $this->oldAttributes['password'];
}
return parent::beforeSave();
}
示例12: beforeSave
/**
* beforeSave if a file is found, upload it, and then save the filename according to the settings
*
*/
function beforeSave(Model $Model, $options = array())
{
if (isset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']])) {
$file = $Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']];
$this->Uploader[$Model->alias]->file = $file;
if ($this->Uploader[$Model->alias]->hasUpload()) {
$fileName = $this->Uploader[$Model->alias]->processFile();
if ($fileName) {
$Model->data[$Model->alias][$this->options[$Model->alias]['fields']['name']] = $fileName;
$Model->data[$Model->alias][$this->options[$Model->alias]['fields']['size']] = $file['size'];
$Model->data[$Model->alias][$this->options[$Model->alias]['fields']['type']] = $file['type'];
} else {
return false;
// we couldn't save the file, return false
}
unset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']]);
} else {
unset($Model->data[$Model->alias]);
}
}
return $Model->beforeSave();
}
示例13: beforeSave
/**
* Выполняет действия перед сохранением записи
*/
public function beforeSave()
{
parent::beforeSave();
}
示例14: beforeSave
function beforeSave($options = array())
{
parent::beforeSave($options);
return true;
}
示例15: beforeSave
/**
* @brief Called before each save operation, after validation. Return a non-true result
* to halt the save.
*
* @link http://api13.cakephp.org/class/model#method-ModelbeforeSave
*
* @param $created True if this save created a new record
* @access public
*
* @return boolean True if the operation should continue, false if it should abort
*/
public function beforeSave($options = array())
{
return parent::beforeSave($options);
}