beforeSave() 공개 메소드

public beforeSave ( Model $model, $options = [] )
$model Model
예제 #1
0
 /**
  * Before save method. Called before all saves
  *
  * Handles setup of file uploads
  *
  * @param Model $model Model instance
  * @param array $options Options passed from Model::save().
  * @return bool
  */
 public function beforeSave(Model $model, $options = array())
 {
     CakeLog::debug('NcUploadBehavior::beforeSave()');
     CakeLog::debug('NcUploadBehavior::beforeSave() $this->settings=' . print_r($this->settings, true));
     CakeLog::debug('NcUploadBehavior::beforeSave() $model->data=' . print_r($model->data, true));
     $fields = array_keys($this->settings[$model->alias]);
     foreach ($fields as $field) {
         if (isset($model->data[$field]['File']['path']) && $model->data[$field]['File']['path'] !== '') {
             $newPath = $this->__realPath($model->data[$field]['File']['path']);
             //CakeLog::debug('NcUploadBehavior::beforeSave() $newPath=' . print_r($newPath, true));
             //CakeLog::debug('NcUploadBehavior::beforeSave() $model->data[\'File\'][\'path\']=' . print_r($model->data['File']['path'], true));
             $this->uploadSettings($model, $field, 'path', $newPath);
             $this->uploadSettings($model, $field, 'thumbnailPath', $newPath);
         }
     }
     return parent::beforeSave($model, $options);
 }
예제 #2
0
 /**
  * Before save method. Called before all saves
  *
  * Handles setup of file uploads
  *
  * @param Model $model Model instance
  * @param array $options Options passed from Model::save().
  * @return bool
  */
 public function beforeSave(Model $model, $options = array())
 {
     $fields = array_keys($this->settings[$model->alias]);
     foreach ($fields as $field) {
         if (isset($model->data[$field]['File']['path']) && $model->data[$field]['File']['path'] !== '') {
             $newPath = $this->__realPath($model->data[$field]['File']['path']);
             $this->uploadSettings($model, $field, 'path', $newPath);
             $this->uploadSettings($model, $field, 'thumbnailPath', $newPath);
         }
     }
     return parent::beforeSave($model, $options);
 }