/** * Creates a new Joke model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Joke(); $model->active_from = date('Y-m-d H:i:s'); if ($model->load(Yii::$app->request->post())) { //print_r(Yii::$app->request->post()); //die(); $model->views = 0; $model->active = 1; $model->create_date = date('Y-m-d H:i:s'); $model->category_ids = Yii::$app->request->post('Joke')['category_ids']; if ($model->save()) { $model->saveCategories(); return $this->redirect(['index']); } } $categoriesList = $this->getCategories(); return $this->render('create', ['categoriesList' => $categoriesList, 'model' => $model]); }