Bước 1 : Kết nối mongodb với yii2 bằng cách vào file : yiiadvanced\common\config\main-local.php
<?php return [ 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2advanced', 'username' => 'root', 'password' => '', 'charset' => 'utf8', ], 'mongodb' => [ 'class' => '\yii\mongodb\Connection', 'dsn' => 'mongodb://@localhost:27017/mydb1', 'options' => [ "username" => "admin", "password" => "admin@123" ] ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => true, ], ], ];
Bước 2 : Kết nối module gii mongodb bằng cách vào file yiiadvanced\common\config\main.php
<?php return [ 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], ], 'modules' => [ // ... 'giimongo' => [ 'class' => 'yii\gii\Module', 'generators' => [ 'mongoDbModel' => [ 'class' => 'yii\mongodb\gii\model\Generator' ] ], ], ] ];
Bước 3 truy cập :http://localhost/yiiadvanced/frontend/web/giimongo
Bắt đầu làm tương tự như gii như video