Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionCreate()
- {
- $this->layout=('//layouts/column1');
- $model=new Tours;
- $model->TouristGuide_id = Yii::app()->user->Guide_id;
- if(isset($_POST['Tours']))
- {
- $model->attributes=$_POST['Tours'];
- $images = CUploadedFile::getInstancesByName('images');
- // proceed if the images have been set
- if (isset($images) && count($images) > 0) {
- // go through each uploaded image
- foreach ($images as $image => $pic) {
- echo $pic->name.'<br />';
- if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/tours/'.$pic->name)) {
- // add it to the main model now
- $img_add = new TourPhotos();
- $img_add->path = $pic->name;
- $img_add->tours_id = $model->id; // this links your picture model to the main model (like your user, or profile model)
- $img_add->save(); // DONE
- }
- else {}
- }}
- }
- $this->render('create',array(
- 'model'=>$model,
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement