Exemplo n.º 1
0
 private function _save($options)
 {
     $model = ActiveRecord::model($options['model'])->findByPk($options['id']);
     //may be you will be need set some attributes before update
     if (isset($options['attributes'])) {
         $model->attributes = $options['attributes'];
     }
     $attribute = $options['attribute'];
     $model->{$attribute} = $options['value'];
     if ($model->saveAttributes(array($attribute))) {
         if (isset($options['unlink_file'])) {
             $file = Yii::getPathOfAlias('webroot') . '/' . $options['unlink_file'];
             if (is_file($file) && FileSystemHelper::isAllowForUnlink($file)) {
                 FileSystemHelper::deleteFileWithSimilarNames(pathinfo($file, PATHINFO_DIRNAME), pathinfo($file, PATHINFO_BASENAME));
             }
         }
         echo $model->{$attribute};
     } else {
         echo $model->getError($attribute);
     }
 }