title: How to solve problem when inserting data in database, Yii2?
body: <p>I can't insert data in the database. I'm using yii2 advanced.</p>
  <p>I have 3 tables: the default user table, post, and category. Each post has one category, and one category can have many posts.
  But when I click on 'Save' in my create form - nothing happens, the page just refreshes. The post table is still empty.</p>
  <p>Here's PostController</p>
  <pre><code>    namespace frontend\controllers;
  
      use Yii;
      use yii\web\Controller;
      use frontend\models\CreateForm;
      use frontend\models\Category;
      use yii\helpers\ArrayHelper;
  
  
      class PostController extends Controller
      {
  public function actionCreate()
  {
      if(Yii::$app-&gt;user-&gt;isGuest)
      {
          return $this-&gt;redirect(['/site/login']);
  
      }
  
      $model = new CreateForm();
      $category = Category::find()-&gt;all();
      $items = ArrayHelper::map($category, 'id', 'name');
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()))
      {
          if ($model-&gt;save())
          {
              Yii::$app-&gt;session-&gt;setFlash(
                  'success',
                  true
  
              );
              return $this-&gt;refresh();
          } else
              {
                  Yii::$app-&gt;session-&gt;setFlash(
                      'success',
                      false
                  );
              }
  
      }
      return $this-&gt;render('create', [
          'model' =&gt; $model,
          'items' =&gt; $items
      ]);
  
  
  
  }
  </code></pre>
  <p>This is CreateForm model</p>
  <pre><code>    namespace frontend\models;
  
      use yii\base\Model;
      use frontend\models\Post;
      use Yii;
  
  
      class CreateForm extends Model
      {
          public $category;
          public $title;
          public $content;
  
  public function attributeLabels()
  {
      return [
          'category' =&gt; 'Category',
          'title' =&gt; 'Title',
          'content' =&gt; 'Content',
      ];
  
  }
  
  public function save()
  {
      $post = new Post();
      $post-&gt;user_id = Yii::$app-&gt;user-&gt;id;
      $post-&gt;category_id = $this-&gt;category;
      $post-&gt;title = $this-&gt;title;
      $post-&gt;content = $this-&gt;content;
      $post-&gt;created_at = time();
  
  
  }
  
     }
  </code></pre>
  <p>And this the view</p>
  <pre><code>    use yii\bootstrap\ActiveForm;
      use yii\bootstrap\Html;
  
      $form = ActiveForm::begin();
      echo $form-&gt;field($model, 'category')-&gt;dropDownList($items);
      echo $form-&gt;field($model, 'title')-&gt;textInput();
      echo $form-&gt;field($model, 'content')-&gt;textInput();
      echo Html::submitButton('Save', ['class' =&gt; 'btn btn-primary']);
      ActiveForm::end();
  </code></pre>
  <p>What am I doing wrong, I can't understand</p>