Beispiel #1
0
 protected function afterSave()
 {
     parent::afterSave();
     $images = CUploadedFile::getInstances($this, 'images');
     if (isset($images) && count($images) > 0) {
         foreach ($images as $k => $img) {
             $imageName = md5(microtime()) . '.jpg';
             if ($img->saveAs($this->getFolder() . $imageName)) {
                 $advImg = new Image();
                 $advImg->goods_id = $this->getPrimaryKey();
                 $advImg->image = $imageName;
                 $advImg->save();
             }
         }
     }
     if ($this->isNewRecord) {
         $count = new Count();
         $count->goods_id = $this->id;
         $count->count = $this->count;
         $count->size = $this->size;
         $count->color = $this->color;
         $count->save();
     } else {
         Count::model()->updateAll(array('goods_id' => $this->id, 'count' => $this->count, 'size' => $this->size, 'color' => $this->color), 'goods_id=:goods_id', array(':goods_id' => $this->id));
     }
 }
Beispiel #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Goods the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Goods::model()->findByPk($id);
     $count = Count::model()->find('goods_id=:goods_id', array(':goods_id' => $id));
     $model->count = $count->count;
     $model->size = $count->size;
     $model->color = $count->color;
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }