Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1.     public function actionCreate()
  2.     {
  3.                 $this->layout=('//layouts/column1');
  4.         $model=new Tours;
  5.  
  6.         $model->TouristGuide_id = Yii::app()->user->Guide_id;
  7.  
  8.         if(isset($_POST['Tours']))
  9.         {
  10.             $model->attributes=$_POST['Tours'];
  11.                        
  12.                $images = CUploadedFile::getInstancesByName('images');
  13.  
  14.             // proceed if the images have been set
  15.             if (isset($images) && count($images) > 0) {
  16.  
  17.                 // go through each uploaded image
  18.                 foreach ($images as $image => $pic) {
  19.                     echo $pic->name.'<br />';
  20.                     if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/tours/'.$pic->name)) {
  21.                         // add it to the main model now
  22.                         $img_add = new TourPhotos();
  23.                         $img_add->path = $pic->name;
  24.                         $img_add->tours_id = $model->id; // this links your picture model to the main model (like your user, or profile model)
  25.  
  26.                         $img_add->save(); // DONE
  27.                     }
  28.                     else {}
  29.                 }}
  30.         }
  31.  
  32.         $this->render('create',array(
  33.             'model'=>$model,
  34.         ));
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement