0

CRUD yii2 using GII

In this article you’ll learn how to create CRUD in yii2 using GII.
This below is sample output :

CRUD yii2 using GIIDEMO HERE

Let’s do it !

CONNECTION

First, configure the database connection in common/config/main-local.php :
config database connection yii2

TABLE

The table name is “book”.
Screenshot from 2015-08-06 23:30:00

GENERATE CRUD USING GII

Access GII on :

http://localhost/your_yii/frontend/web/index.php?r=gii

And will be display like this :
GII in yii2

1) First, we must create a model.
Click a button ‘start’ at the Model Generator. Then fill the input ‘Table name’ below with ‘book’ :


Model generator yii2
Click Preview and then click Generate.

generated model generator yii2

2) Next, click ‘CRUD Generator’ at the top left menu. Then fill the input like below
CRUD Generator in yii2
Click Preview and then click generate.

3) Finish!!! You can try the CRUD by URL below :

http://localhost/your_yii/frontend/web/index.php?r=book

Screenshot from 2015-07-30 16:48:04

if you get error like this :

Unable to find ‘frontend\controllers\BookController’ in file: /var/www/html/yii2_advanced/frontend/controllers/BookController.php. Namespace missing?

Open frontend/controllers/BookController.php, find :

namespace app\controllers

change it to

namespace frontend\controllers

Ambar Hasbiyatmoko

Hello, I'm web developer. Passionate about programming, web server, and networking.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.