public function beforeSave()
 {
     $dataDir = Yii::getPathOfAlias('backend.data');
     $field = 'image';
     $uploadFile = CUploadedFile::getInstance($this, $field);
     if (!$uploadFile) {
         return parent::beforeSave();
     }
     $this->{$field} = $uploadFile;
     $dirPath = $dataDir . '/' . strtolower(__CLASS__);
     if (!file_exists($dirPath)) {
         mkdir($dirPath, 0777, true);
     }
     if (!$this->{$field} || !$this->{$field}->saveAs($dirPath . '/' . $field . '_' . $this->id)) {
         Yii::app()->user->setFlash('danger', 'problem saving image for field: ' . $field);
     }
     return parent::beforeSave();
 }
Beispiel #2
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return BoxItem the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }