use yii\helpers\ArrayHelper; use app\models\ServiceCategories; use dosamigos\ckeditor\CKEditor; /* @var $this yii\web\View */ /* @var $model app\models\Services */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="services-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(ServiceCategories::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'text')->widget(CKEditor::className(), []); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function actionIndex() { Yii::$app->session->removeFlash('activeButton'); $categories = ServiceCategories::find()->with('services')->all(); return $this->render('index', ['categories' => $categories]); }
/** * Finds the ServiceCategories model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ServiceCategories the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ServiceCategories::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }