Example #1
0
 /**
  * Creates a new Hashtag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionAdd()
 {
     $model = new Hashtag();
     $modelDescription = new HashtagDescription();
     if ($model->load(Yii::$app->request->post()) && $modelDescription->load(Yii::$app->request->post())) {
         $modelDescription->hashtag = 0;
         $modelDescription->user = !Yii::$app->user->isGuest ? Yii::$app->user->id : 0;
         if ($model->validate() && $modelDescription->validate()) {
             $model->save();
             $modelDescription->hashtag = $model->id;
             $modelDescription->save();
             return $this->redirect(['view', 'tag' => $model->tag]);
         }
     }
     return $this->render('create', ['model' => $model, 'modelDescription' => $modelDescription]);
 }
Example #2
0
 public function getDescriptions()
 {
     return $this->hasMany(HashtagDescription::className(), ['hashtag' => 'id'])->orderBy('likes desc, id desc');
 }