(02) The basic config of Yii2

  1. Please read the manual/documentation – this will help you to understand the structure of Yii2 framework – how files are stored/organized, and how the framework hangs together. I made a mistake trying to jump in without having the basic knowledge of what Yii2 is about.
  2. The concept of MVC (Model View Controller) has to be understood as well. The video tutorial in the previous post should give you an idea. Any MVC tutorial on Youtube would suffice as well.
  3. Gii is a very important tool – if you want to use Yii with Database. Make sure Gii is working – else you will have to create lots of code from scratch. Gii is already pre-installed with Yii2 basic.
  4. Some issues when trying to access Gii:

A. Database Exception

This issue is actually caused by the config in the file db.php
(C:\Users\<Yii Path>\basic\config\db.php)

<?php

return [
‘class’ => ‘yii\db\Connection’,
// ‘dsn’ => ‘mysql:host=localhost;dbname=yii2basic’,
// ‘username’ => ‘root’,
// ‘password’ => ”,
‘dsn’ => ‘mysql:host=localhost;dbname=uXXXXX_yyyyy1’,
‘username’ => ‘uXXXXXX_aYYYYY’,
‘password’ => ‘XXXXXXyyyyyyyy’,
‘charset’ => ‘utf8’,
];

B. Forbidden 403

This is caused by Gii config that only allows certain IPs to access it (security purpose). To fix this issue, check your external IP (how internet sees your machine – either using sites like whatismyip.com ) and then add it to Gii config.

C:\Users\<Yii Path> \basic\vendor\yiisoft\yii2-gii\Module.php

 

*/
class Module extends \yii\base\Module implements BootstrapInterface
{
/**
* @inheritdoc
*/
public $controllerNamespace = ‘yii\gii\controllers’;
/**
* @var array the list of IPs that are allowed to access this module.
* Each array element represents a single IP filter which can be either an IP address
* or an address with wildcard (e.g. 192.168.0.*) to represent a network segment.
* The default value is `[‘127.0.0.1’, ‘::1’]`, which means the module can only be accessed
* by localhost.
*/

public $allowedIPs = [‘127.0.0.1’, ‘::1’, ‘1XX.1XX.1X.1XX’,’6X.XX.1XX.1XX’,’6X.XX.1XX.2XX’];
/**

Leave a Reply

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