halonode / proyi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yii 2 Starter Kit

This is Yii2 start application template.

It was created and developing as a fast start for building an advanced sites based on Yii2.

It covers typical use cases for a new project and will help you not to waste your time doing the same work in every project

FEATURES

DEMO

http://yii2-starter-kit.terentev.net

http://backend.yii2-starter-kit.terentev.net

administrator role account

Login: webmaster
Password: webmaster

manager role account

Login: manager
Password: manager

user role account

Login: user
Password: user

REQUIREMENTS

The minimum requirement by this application template that your Web server supports PHP 5.4.0.

INSTALLATION

Before installation

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

Install composer-asset-plugin needed for yii assets management

php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta4"

Install from GitHub (preferred way)

Extract the github archive file or clone this repository.

git clone https://github.com/trntv/yii2-starter-kit.git

After extraction run

php composer.phar install

Install via Composer

You can install this application template with composer using the following command:

php composer.phar create-project --prefer-dist --stability=dev trntv/yii2-starter-kit

Application configuration process include:

  1. Edit configuration templates if you need
  2. Initialise application
  3. Configure environment local settings
  4. Apply migrations
  5. Initialise RBAC

1. Configuration templates

Environment specific configuration files stored in environments/some-environment directory. These folders contain config templates that will be copied to your config in initialization process, so your can change them to fit your needs on specific environment. They are stored under the VCS.

2. Initialization

Initialise application

./init // init.bat for windows

Initialization tools will copy config (*-local) files where you can override settings specific for application local environment. NOTE: environments/*-local files are excluded from git in .gitignore

3. Environment

You should set it in your .env file, web server config or change in frontend/web/index.php, backend/web/index.php, console/yii files. Default environment is dev.

3.1 Database

Edit the file .env with your data:

MYSQL_DSN           = mysql:host=127.0.0.1;port=3306;dbname=yii2-starter-kit
MYSQL_USERNAME      = user
MYSQL_PASSWORD      = password

NOTE: Yii won't create the database for you, this has to be done manually before you can access it.

3.2 Web Server

You should configure web server with three different web roots:

example.com => path/to/yii2-starter-kit/frontend/web

backend.example.com => path/to/yii2-starter-kit/backend/web

storage.example.com => path/to/yii2-starter-kit/storage

NOTE: Preferable web server for me, personally, is nginx, so there is a nginx.conf file with an example nginx config.

3.3 Application urls

Set your current application urls in .env

FRONTEND_URL    = http://yii2-starter-kit.localhost
BACKEND_URL     = http://backend.yii2-starter-kit.localhost
STORAGE_URL     = http://storage.yii2-starter-kit.localhost

4. Apply migrations

php console/yii migrate

5. Initialise RBAC config

php console/yii rbac/init

IMPORTANT: without rbac/init you CAN'T LOG IN into backend

Demo user

Login: webmaster
Password: webmaster

COMPONENTS

I18N

If you want to store application messages in DB and to have ability to edit them from backend, run:

php console/yii message/migrate @common/config/messages/php.php @common/config/messages/db.php

it will copy all existing messages to database

Then uncomment config for DbMessageSource in

common/config/_base.php

KeyStorage

Key storeage is a key-value storage to store different information. Application params for example. Values can be stored both via api or by backend CRUD component.

Yii::$app->keyStorage->set('key', 'value');
Yii::$app->keyStorage->get('articles-per-page');

ExtendedMessageController

This controller extends default MessageController to provide some useful actions

Migrate messages between different message sources: yii message/migrate @common/config/messages/php.php @common/config/messages/db.php

Replace source code language: yii message/replace-source-language @path language-LOCALE

Remove Yii::t from code yii message/replace-source-language @path

Behaviors

CacheInvalidateBehavior

 public function behaviors()
 {
     return [
         [
             'class' => `common\components\behaviors\CacheInvalidateBehavior`,
             'tags' => [
                  'awesomeTag',
                   function($model){
                       return "tag-{$model->id}"
                  }
              ],
             'keys' => [
                  'awesomeKey',
                  function($model){
                      return "key-{$model->id}"
                  }
              ]
         ],
     ];
 }

GlobalAccessBehavior

usage example in backend\config\web.php

Widgets configurable from backend

Carousel

...

DbText

...

DbMenu

echo common\components\widgets\DbMenu::widget([
      'key'=>'stored-menu-key',
      /* any other option from \yii\widgets\Menu */ 
])

Input widgets

Grid

EnumColumn

 [
      'class'=>'\common\components\grid\EnumColumn',
      'attribute'=>'status',
      'enum'=>User::getStatuses() // [0=>'Deleted', 1=>'Active']
 ]

Many more useful components

  • common\components\behaviors\GlobalAccessBehavior allows to set access rules for your application in application config
  • common\components\validators\JsonValidator validates a value to be a valid json
  • ElFinder - (https://github.com/MihailDev/yii2-elfinder)
  • RBAC OwnModelRule - simple rule to check if the current user is model owner

OTHER

Updates

Add remote repository upstream.

git remote add upstream https://github.com/trntv/yii2-starter-kit.git

Fetch latest changes from it

git fetch upstream

Merge these changes into your repository

git merge upstream/master

IMPORTANT: there might be a conflicts between upstream and your code. You should resolve conflicts on your own

READ MORE

https://github.com/yiisoft/yii2/blob/master/apps/advanced/README.md https://github.com/yiisoft/yii2/tree/master/docs

Have any questions?

mail to eugine@terentev.net

NOTE

This template was created mostly for developer NOT for end users. This is a point where you can begin your application, rather than creating it from scratch. Good luck!

About

License:Other


Languages

Language:PHP 97.0%Language:JavaScript 1.5%Language:CSS 0.9%Language:Shell 0.7%