Can't get newly added db table columns to show up in Gii

Hi all,

Pretty new to Yii2 here. Super excited about using it, but have been running into an issue I can’t seem to resolve.

I have a table called employees in my database, for which I used Gii to generate the models / controllers / views. All good at first.

Then I needed to add some additional fields. I went ahead and added the new fields using MySQL via the command line, then I tried using Gii to regenerate the models, controllers and views again. But for the life of me, I can’t get them to display! The fields I added were:




They are in the code that is being generated, but they just won’t display when you visit my … ?r=employees URL.

Here is the model code in models/Employees.php


namespace app\models;

use Yii;


 * This is the model class for table "employees".


 * @property integer $id

 * @property string $hire_date

 * @property string $first

 * @property string $last

 * @property string $address

 * @property string $address_line_2

 * @property string $postal

 * @property string $phone

 * @property string $deparment

 * @property string $hourly_rate_base

 * @property string $status

 * @property string $title

 * @property string $writeups

 * @property string $city


class Employees extends \yii\db\ActiveRecord



     * @inheritdoc


    public static function tableName()


        return 'employees';



     * @inheritdoc


    public function rules()


        return [

            [['hire_date'], 'safe'],

            [['hourly_rate_base'], 'number'],

            [['first', 'last', 'city'], 'string', 'max' => 50],

            [['address', 'address_line_2', 'title'], 'string', 'max' => 100],

            [['postal'], 'string', 'max' => 6],

            [['phone'], 'string', 'max' => 16],

            [['deparment', 'status'], 'string', 'max' => 20],

            [['writeups'], 'string', 'max' => 5000],




     * @inheritdoc


    public function attributeLabels()


        return [

            'id' => 'ID',

            'hire_date' => 'Hire Date',

            'first' => 'First',

            'last' => 'Last',

    [b]        'address' => 'Address',

            'address_line_2' => 'Address Line 2',

            'postal' => 'Postal',[/b]

            'phone' => 'Phone',

            'deparment' => 'Deparment',

            'hourly_rate_base' => 'Hourly Rate Base',

            'status' => 'Status',

            'title' => 'Title',

            'writeups' => 'Writeups',

        [b]    'city' => 'City',[/b]




Here is the views/employees/view.php code:


use yii\helpers\Html;

use yii\widgets\DetailView;

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

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

$this->title = $model->title;

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

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


<div class="employees-view">

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


        <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>

        <?= Html::a('Delete', ['delete', 'id' => $model->id], [

            'class' => 'btn btn-danger',

            'data' => [

                'confirm' => 'Are you sure you want to delete this item?',

                'method' => 'post',


        ]) ?>


    <?= DetailView::widget([

        'model' => $model,

        'attributes' => [





  [b]          'address',









 [b]           'city',[/b]


    ]) ?>


And here is the views/employees/_form.php code


use yii\helpers\Html;

use yii\widgets\ActiveForm;

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

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

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


<div class="employees-form">

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

    <?= $form->field($model, 'hire_date')->textInput() ?>

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

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

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

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

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

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

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

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

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

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

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

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

    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRec

ord ? 'btn btn-success' : 'btn btn-primary']) ?>


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


Here’s a screenshot with the fields I added missing:



Now, if I click the ‘Create Employees’ button, the new fields ARE there. It’s just on this page (r=employees) that I can’t get it to show up!

I have tried clearing all the assets in the web/assets folder, I tried regenerating everything multiple times – no success. I am on a bit of a time crunch and would really appreciate any help you can offer to resolve this issue for me.

Many thanks!


Ok, I finally figured out which file generates the view that I was having the problem with. It was the "GRID" view, and the file was views/employees/index.php.

Oddly, the newly added fields and several others are commented out! Here’s what the file looks like:


use yii\helpers\Html;

use yii\grid\GridView;

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

/* @var $searchModel app\models\EmployeesSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Employees';

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


<div class="employees-index">

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

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


        <?= Html::a('Create Employees', ['create'], ['class' => 'btn btn-success']) ?>


    <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],






            // 'address_line_2',

            // 'postal',

            // 'phone',

            // 'deparment',

            // 'hourly_rate_base:url',

            // 'status',

            // 'title',

            // 'writeups',

            // 'city',

            ['class' => 'yii\grid\ActionColumn'],


    ]); ?>


Would love to know why! Also not sure why for ‘hourly_rate_base’ there is a ‘:url’ on the end of it.


Gii make only a stub code, pretty good one, which in many case is production ready but still a stub code.

If the table has many columns and it enable all of them the grid became unreadable.

That’s why the lasts column are commented.

Normally a grid should contain these column that are useful for searching the record and identifying it univocly.

For :URLs this is a formatter, gii try to chose a formatter basing the choice on the column name/type.

Making your own gii template is pretty easy in case you are not satisfied with the default one.

Thanks for the explanation Roberto.

With respect to the :url thing, it does look like a bug, because it’s treating a decimal type column from the db into a URL in the view.

Thanks again,


The filed name is


and the code that chose the format is:

	public function generateColumnFormat($column)


    	if ($column->phpType === 'boolean') {

        	return 'boolean';

    	} elseif ($column->type === 'text') {

        	return 'ntext';

    	} elseif (stripos($column->name, 'time') !== false && $column->phpType === 'integer') {

        	return 'datetime';

    	} elseif (stripos($column->name, 'email') !== false) {

        	return 'email';

    	} elseif ([b]stripos($column->name, 'url')[/b] !== false) {

        	return 'url';

    	} else {

        	return 'text';



So rather than a bug I would label it as not enough smart.

That line should be something like:

	} elseif ([b]stripos(&#036;column-&gt;name, 'url')[/b] &#33;== false &amp;&amp; &#036;column-&gt;phpType === 'string') {

But it still would fail in many cases, ie:


which is a description field and not and url, or


which is a url and is would be shown as normal text