public function actionCreate() { $model = new Category(); if (isset($_POST['Category'])) { $model->setAttributes($_POST['Category']); $relatedData = array('films' => $_POST['Category']['films'] === '' ? null : $_POST['Category']['films']); if ($model->saveWithRelated($relatedData)) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->category_id)); } } } $this->render('create', array('model' => $model)); }