Yii 2.0: yii2-improved-basic-template

This template is remake of default basic template, with extra functionalities included and is shared hosting friendly.


Yii2-basic-template is based on yii2-app-basic created by yii2 core developers, but it also uses some of the features presented in their advanced template too. There are several upgrades made to this template.

  1. This template comes with almost all features that default yii2-app-advanced has.
  2. It has additional features listed in the next section of this guide.
  3. Application structure has been changed to be 'shared hosting friendly'.

GitHub source: Click to see
Forum topic: Click to ask
Demo page: Click to try
Tutorial: Click to learn


  • Signup with/without account activation
    • You can chose whether or not new users need to activate their account using email account activation system before they can log in.
  • Login using email/password or username/password combo.
    • You can chose how users will login into system. They can log in either by using their username|password combo or email|password.
  • Rbac tables are installed with other migrations when you run yii migrate command.
    • RbacController's init() action will insert 5 roles and 2 permissions in our rbac tables created by migration.
    • Roles can be easily assigned to users by administrators of the site.
  • Session data is stored in _protected/session folder.
  • System setting are stored in config/params.php file.
  • Theming is supported out of the box.
  • Translation is supported out of the box.
  • Administrator+ roles can manage users.
  • Password strength validation and strength meter are included out of the box.
  • Simple role management is included out of the box.
  • Code is heavily commented out.


Note: I am assuming that you know how to: install and use Composer, and install additional packages/drivers that may be needed for you to run everything on your system. In case you are new to all of this, you can check my guides for installing default yii2 application templates on Windows and Linux Ubuntu/Mint operating systems, posted on http://www.freetuts.org .

1) Create database that you are going to use for your application (you can use phpMyAdmin or any other tool you like).

2) Now open up your console and cd to your web root directory, for example:

cd /var/www/sites/

3) Run the Composer create-project command:

composer create-project nenad/yii2-basic-template basic

4) Now you need to tell your application to use database that you have previously created. Open up main-local.php config file in


and adjust your connection credentials.

5) Back to the console. It is time to run yii migrations that will create necessary tables in our database. Move to the _protected folder and execute ./yii migrate command:

cd basic/_protected/
./yii migrate

or if you are on Windows:

yii migrate

6) Execute rbac controller init action that will populate our rbac tables with default roles and permissions:

./yii rbac/init

or if you are on Windows:

yii rbac/init

You are done, you can start your application in your browser.

Info: First user that signs up will get 'theCreator' (super admin) role. This is supposed to be you. This role have all possible super powers :-) . Every other user that signs up after the first one will NOT get any role by default. This is because authenticated user (@ by default) is same like our member role.


If you want to run tests you should create additional database that will be used to store your testing data. Usually testing database will have the same structure like the production one. I am assuming that you have Codeception installed globally, and that you know how to use it. Here is how you can set up everything easily:

1) Let's say that you have created database called basic. Go create the testing one called basic_tests.

2) Inside your db.php config file change database you are going to use to basic_tests.

3) Open up your console and cd to the _protected folder of your application.

4) Run the migrations again: ./yii migrate or if you are on Windows yii migrate

5) Run rbac/init again: ./yii rbac/init or if you are on Windows yii rbac/init

6) Now you can tell your application to use your basic database again instead of basic_tests. Adjust your db.php config file again.

7) Now you are ready to tell Codeception to use basic_tests database.

Inside: _protected/tests/codeception/config/config.php file tell your db to use basic_tests database.

8) Start your php server inside the root of your application:

php -S localhost:8080

9) Move to _protected/tests , run codecept build and then run your tests.

Directory structure

    assets/              contains assets definition
    components/          contains custom made application components
    config/              contains application configurations
    console              contains console commands (controllers and migrations)
    controllers/         contains Web controller classes
    helpers/             contains helper classes
    mail/                contains view files for e-mails
    models/              contains model classes
    rbac/                contains role based access control classes
    runtime/             contains files generated during runtime
    tests/               contains various tests for the basic application
    views/               contains view files for the Web application
    widgets/             contains widgets
assets                   contains application assets generated during runtime
themes                   contains your themes

Version 2.3.0 changes

1) Adds components folder to the _protected folder, and Aliases class in it.
2) Articles have been removed from the template.
3) Themes have been changed.
4) A lot of code improvements have been done.
5) More translation messages have been added.
6) We are using password strength widgets made by Kartik V. now.

Password strength guide

Since 1.1.1 version has been released, password strength extension has been included as a core part of improved templates. Usage is very simple:

In our signup, user create/update and password reset forms password strength meter is always displayed when users are entering their password. This will give them visual representation of their password strength.
But this is not all. As The Creator you have option in your settings "Force Strong Password" that you can use. If you turn it on, users will be forced to use strong passwords according to preset you chose. For example if you use normal preset, users will be forced to use at least 8 characters long password, with at least one upper-case and one lower-case letter, plus at least one digit.

Choosing presets:

By default normal preset is used for signup and user create/update forms. For password reset we are using custom made preset, if you want to customize which presets is used, see SignupForm model, User model and ResetPasswordForm model. You will see rules declared for using strong passwords. Presets are located in vendor/kartik-v/yii2-password/presets.php. You can chose some other preset declared in presets.php, or create new ones.

Total 5 comments

#19811 report it
ahmed.ismail at 2016/03/20 06:56am
Mongo db

Hi Many thanks for your good work, Now I am about to start working in a project with mongoDB, is this template can be customized to use mongoDB?

#18647 report it
Nenad Zivkovic at 2014/12/05 12:09pm

This tutorial may help you: click to learn

Also, after you do everything explained there, please make sure that you have set up you db credentials right. Plus make sure that you are using PHP 5.4+

#18646 report it
salang at 2014/12/05 09:34am
Nenad Zivkovic

Thanks for your prompt reply. I am using ubuntu kylin 14.10 with xampp package. After changing localhost to I got the same error messages as appended below:

Yii Migration Tool (based on Yii v2.0.0)

Exception 'yii\db\Exception' with message 'could not find driver'

in /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Connection.php:534

Stack trace:

0 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Connection.php(836): yii\db\Connection->open()

1 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Connection.php(823): yii\db\Connection->getMasterPdo()

2 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Command.php(208): yii\db\Connection->getSlavePdo()

3 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Command.php(813): yii\db\Command->prepare(true)

4 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Command.php(350): yii\db\Command->queryInternal('fetchAll', NULL)

5 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/mysql/Schema.php(198): yii\db\Command->queryAll()

6 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/mysql/Schema.php(97): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema))

7 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Schema.php(139): yii\db\mysql\Schema->loadTableSchema('migration')

8 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/controllers/MigrateController.php(125): yii\db\Schema->getTableSchema('{{%migration}}', true)

9 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(604): yii\console\controllers\MigrateController->getMigrationHistory(NULL)

10 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(99): yii\console\controllers\BaseMigrateController->getNewMigrations()

11 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)

12 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)

13 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)

14 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction('', Array)

15 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction('', Array)

16 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runAction('migrate', Array)

17 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Application->runAction('migrate', Array)

18 /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))

19 /opt/lampp/htdocs/basic_improved/_protected/yii(25): yii\base\Application->run()

20 {main}

#18640 report it
Nenad Zivkovic at 2014/12/04 09:15am

Most likely it is your system config. If you are using packages like MAMP, XAMPP or other, you may need to change "localhost" to "" in your db.php configuration file. Also if you are on Linux you may need to install some other additional packages like php5-mysql and stuff like that. If localhost trick do not work, tell me which OS you are using and are you using xAMP packages.

#18638 report it
salang at 2014/12/04 04:57am

I followed your instruction upto step 5 and got the following error:

./yii migrate

Yii Migration Tool (based on Yii v2.0.0)

Exception 'yii\db\Exception' with message 'could not find driver'

in /opt/lampp/htdocs/basic_improved/_protected/vendor/yiisoft/yii2/db/Connection.php:534

Is there anything wrong with Yii Migration Tool?

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet