/**
  * Creates a new Tweet model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tweet();
     if ($model->load(Yii::$app->request->post())) {
         $model->owner = Yii::$app->user->identity->username;
         $date = new \DateTime();
         $model->timestamp = $date->getTimestamp();
         if ($model->save()) {
             //Upload images if need be.
             $image = UploadedFile::getInstances($model, 'image');
             \Cloudinary::config(array("cloud_name" => "dxqmggd5a", "api_key" => "314154111631994", "api_secret" => "KE-AgYwX8ecm8N2omI22RDVmFv4"));
             foreach ($image as $file) {
                 $uploadResult = \Cloudinary\Uploader::upload($file->tempName);
                 $myConnection = new MediaConnections();
                 $myConnection->tweet = $model->id;
                 $myConnection->url = $uploadResult['url'];
                 $myConnection->timestamp = $model->timestamp;
                 $myConnection->save();
             }
             User::findByUsername($model->owner)->createTweet();
             return $this->redirect(Yii::$app->request->referrer);
         }
     }
     return $this->render('create', ['model' => $model]);
 }