controllerClass); $modelClass = StringHelper::basename($generator->modelClass); $searchModelClass = StringHelper::basename($generator->searchModelClass); if ($modelClass === $searchModelClass) { $searchModelAlias = $searchModelClass.'Search'; } $pks = $generator->getTableSchema()->primaryKey; $urlParams = $generator->generateUrlParams(); $actionParams = $generator->generateActionParams(); $actionParamComments = $generator->generateActionParamComments(); echo " namespace controllerClass, '\\')) ?>; use modelClass, '\\') ?>; use searchModelClass, '\\') ?> as ; use baseControllerClass, '\\') ?>; use yii\web\HttpException; use yii\web\VerbFilter; /** * implements the CRUD actions for model. */ class extends baseControllerClass) . "\n" ?> { public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], ]; } /** * Lists all models. * @return mixed */ public function actionIndex() { $searchModel = new ; $dataProvider = $searchModel->search($_GET); return $this->render('index', [ 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, ]); } /** * Displays a single model. * * @return mixed */ public function actionView() { return $this->render('view', [ 'model' => $this->findModel(), ]); } /** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ; if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', ]); } else { return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing model. * If update is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionUpdate() { $model = $this->findModel(); if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', ]); } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing model. * If deletion is successful, the browser will be redirected to the 'index' page. * * @return mixed */ public function actionDelete() { $this->findModel()->delete(); return $this->redirect(['index']); } /** * Finds the model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @return the loaded model * @throws HttpException if the model cannot be found */ protected function findModel() { \$$pk"; } $condition = '[' . implode(', ', $condition) . ']'; } ?> if (($model = ::find()) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } } }