CRUD customize views?

I’ve made an CRUD table with the standard views (index, create etc)

I tried to change one of the $form->field->textInput into an dropdownlist, but for some reason it won’t change it to an dropdownlist. It just shows the standard form, with the textInput, even when I remove the textField

this is _formCreate:




<?php


use yii\helpers\Html;

use yii\widgets\ActiveForm;

use yii\helpers\ArrayHelper;

use app\models\User;


/* @var $this yii\web\View */

/* @var $model app\models\Projects */

/* @var $form yii\widgets\ActiveForm */

?>


<div class="projects-form">


    <?php $form = ActiveForm::begin(); ?>


    <?= $form->field($model, 'project_naam')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'Werknemers_id')->dropDownList(ArrayHelper::map(User::find()->all(), 'username', 'id' )) ?>


    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

    </div>


    <?php ActiveForm::end(); ?>


</div>



and this is the create view:




<?php


use yii\helpers\Html;




/* @var $this yii\web\View */

/* @var $model app\models\Projects */


$this->title = 'Create Project';

$this->params['breadcrumbs'][] = ['label' => 'Projects', 'url' => ['index']];

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="projects-create">


    <h1><?= Html::encode($this->title) ?></h1>


    <?= $this->render('_form', [

        'model' => $model,

    ]) ?>


</div>




Try rendering the right form?




<?= $this->render('_formCreate', [

        'model' => $model,

    ]) ?>




Oh sorry I forgot to put that I already tried that,

But it still doesn’t work…

Which field is it?

This was the original:




<?php


use yii\helpers\Html;

use yii\widgets\ActiveForm;

use yii\helpers\ArrayHelper;

use app\models\User;


/* @var $this yii\web\View */

/* @var $model app\models\Projects */

/* @var $form yii\widgets\ActiveForm */

?>


<div class="projects-form">


    <?php $form = ActiveForm::begin(); ?>


    <?= $form->field($model, 'project_naam')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'Werknemers_id')->textInput(['maxlength' => true]) ?>

   

    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

    </div>


    <?php ActiveForm::end(); ?>


</div>



and I changed it to:





<?php


use yii\helpers\Html;

use yii\widgets\ActiveForm;

use yii\helpers\ArrayHelper;

use app\models\User;


/* @var $this yii\web\View */

/* @var $model app\models\Projects */

/* @var $form yii\widgets\ActiveForm */

?>


<div class="projects-form">


    <?php $form = ActiveForm::begin(); ?>


    <?= $form->field($model, 'project_naam')->textInput(['maxlength' => true]) ?>

   

 <?= $form->field($model, 'Werknemers_id')->dropDownList(ArrayHelper::map(User::find()->all(), 'username', 'id' )) ?>




    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

    </div>


    <?php ActiveForm::end(); ?>


</div>




And you are saying that "Werknemers_id" is still a text field? Are you 100% certain that you are editing the right view?

Yes im 100% sure… I checked the url 10000000 times…

Easy way to tell if you are editing the right file is to add a typo somewhere. If PHP throws an error, it’s the right file.

I tried changing $this->title to something different but it doesnt seem to change anything…

EDIT: I’ve made an typo, but PHP doesn’t throw an error. Maybe it has something to do with my controller?




<?php


namespace backend\controllers;


use Yii;

use app\models\Projects;

use backend\controllers\SearchProjects;

use yii\web\Controller;

use yii\web\NotFoundHttpException;

use yii\filters\VerbFilter;


/**

 * ProjectsController implements the CRUD actions for Projects model.

 */

class ProjectsController extends Controller

{

    /**

     * @inheritdoc

     */

    public function behaviors()

    {

        return [

            'verbs' => [

                'class' => VerbFilter::className(),

                'actions' => [

                    'delete' => ['POST'],

                ],

            ],

        ];

    }


    /**

     * Lists all Projects models.

     * @return mixed

     */

    public function actionIndex()

    {

        $searchModel = new SearchProjects();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }


    /**

     * Displays a single Projects model.

     * @param integer $id

     * @return mixed

     */

    public function actionView($id)

    {

        return $this->render('view', [

            'model' => $this->findModel($id),

        ]);

    }


    /**

     * Creates a new Projects model.

     * If creation is successful, the browser will be redirected to the 'view' page.

     * @return mixed

     */

    public function actionCreate()

    {

        $model = new Projects();


        if ($model->load(Yii::$app->request->post()) && $model->save()) {

            return $this->redirect(['view', 'id' => $model->Werknemers_id]);

        } else {

            return $this->render('create', [

                'model' => $model,

            ]);

        }

    }


    /**

     * Updates an existing Projects model.

     * If update is successful, the browser will be redirected to the 'view' page.

     * @param integer $id

     * @return mixed

     */

    public function actionUpdate($id)

    {

        $model = $this->findModel($id);


        if ($model->load(Yii::$app->request->post()) && $model->save()) {

            return $this->redirect(['view', 'id' => $model->Werknemers_id]);

        } else {

            return $this->render('update', [

                'model' => $model,

            ]);

        }

    }


    /**

     * Deletes an existing Projects model.

     * If deletion is successful, the browser will be redirected to the 'index' page.

     * @param integer $id

     * @return mixed

     */

    public function actionDelete($id)

    {

        $this->findModel($id)->delete();


        return $this->redirect(['index']);

    }


    /**

     * Finds the Projects model based on its primary key value.

     * If the model is not found, a 404 HTTP exception will be thrown.

     * @param integer $id

     * @return Projects the loaded model

     * @throws NotFoundHttpException if the model cannot be found

     */

    protected function findModel($id)

    {

        if (($model = Projects::findOne($id)) !== null) {

            return $model;

        } else {

            throw new NotFoundHttpException('The requested page does not exist.');

        }

    }

}




  1. What’s the URL you are accessing?

  2. What’s the content of the “create.php” view?

  3. What’s the exact name of the file you are editing?

1: http://localhost/bouw7_1/backend/web/index.php?r=projects%2Fcreate

2:




<?php


use yii\helpers\Html;




/* @var $this yii\web\View */

/* @var $model app\models\Projects */


$this->title = 'Create Project';

$this->params['breadcrumbs'][] = ['label' => 'Projects', 'url' => ['index']];

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="projects-create">


    <h1><?= Html::encode($this->title) ?></h1>


    <?= $this->render('_formCreate', [

        'model' => $model,

    ]) ?>


</div>




3: create.php & _formCreate.php

Any they are both in "backend/views/projects" folder?

Thank you. I got it. I was editing the wrong view…