Jsparo30
Jsparo30

Reputation: 405

How to add custom column in the database and make it appear in yii2 (Advanced Template)?

I am new to yii2 framework. I added a column in a table in the database and its value not appears in the gridview (it gives me notset). I don't want to regenerate the model, controller and views using gii. How to do that?

Upvotes: 1

Views: 76

Answers (2)

Sohel Ahmed Mesaniya
Sohel Ahmed Mesaniya

Reputation: 3450

You don't need to regenerate Models, Views and Controllers through Gii again. You can accomplish this by :

In your view file (probably index.php)

...
<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],


        // your other attribute here
        'your_new_column_name',

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>
...

Thats it.

Upvotes: 0

zuups
zuups

Reputation: 1150

If you don't want to regenerate your code with gii (perhaps because of changes you have made), you can still use gii's preview and diff functions to get hints what has to be added to your code and do it manually...

Upvotes: 3

Related Questions