2017 © Pedro Peláez
 

project yii2-advanced-start

Yii 2 Advanced start template on Yii2

image

dominus77/yii2-advanced-start

Yii 2 Advanced start template on Yii2

  • Sunday, July 29, 2018
  • by dominus77
  • Repository
  • 3 Watchers
  • 3 Stars
  • 148 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 10 Versions
  • 47 % Grown

The README.md

Yii2 Start Project Advanced Template

Latest Stable Version License build Scrutinizer Code Quality Code Intelligence Status Total Downloads, (*1)

The application is built using advanced pattern and has a modular structure. Backend part uses AdminLTE template Available console user management commands and RBAC system., (*2)

Base components

Pages (backend AdminLTE template) - Home - Users - RBAC - Profile - Login - Maintenance, (*3)

Pages (frontend) - Home - Contact - Sign Up - Profile - Login - Maintenance, (*4)

Modules - main - rbac - users, (*5)

Functional - Reset password - Confirmation by email - Last visit - RBAC Management from the console and web interface - Maintenance, (*6)

System - RBAC (DbManager) - Manage users - Manage maintenance - Console commands - i18n, (*7)

CSS Themes Bootstrap

The template includes the of the CSS Theme Bootstrap, (*8)

Switching the theme occurs in the /frontend/config/main.php, (*9)

Requirements

The minimum requirement by this project template that your Web server supports PHP 5.6.0., (*10)

Directory Structure

api
    components/          contains components api application
    config/              contains api application configurations
    messages/            contains i18n api application
    modules/             contains modules api version application
    runtime/             contains files generated during runtime
    tests/               contains tests for api application
    web/                 contains the entry script
common
    assets/              contains application assets such as JavaScript and CSS
    components/          contains components frontend, backend and console
    config/              contains shared configurations
    mail/                contains layouts files for e-mails
    messages/            contains i18n backend frontend
    models/              contains model classes used in both backend and frontend    
    tests/               contains tests for common classes
    widgets/             contains widgets backend and frontend
console
    components/          contains console components
    config/              contains console configurations
    controllers/         contains console controllers (commands)
    messages/            contains i18n console
    migrations/          contains database migrations
    models/              contains console-specific model classes
    runtime/             contains files generated during runtime
backend
    assets/              contains application assets such as JavaScript and CSS
    components/          contains backend components
    config/              contains backend configurations
    controllers/         contains Web controller classes
    messages/            contains i18n backend
    models/              contains backend-specific model classes
    runtime/             contains files generated during runtime
    tests/               contains tests for backend application
    views/               contains view files for the Web application
    web/                 contains the entry script and Web resources
    widgets/             contains backend widgets
frontend
    assets/              contains application assets such as JavaScript and CSS
    config/              contains frontend configurations
    controllers/         contains Web controller classes
    messages/            contains i18n frontend
    models/              contains frontend-specific model classes
    runtime/             contains files generated during runtime
    tests/               contains tests for frontend application
    views/               contains view files for the Web application
    web/                 contains the entry script and Web resources
    widgets/             contains frontend widgets
vendor/                  contains dependent 3rd-party packages
environments/            contains environment-based overrides
modules/
    main/               contains module main
        controllers/    contains module Web controller classes
            backend/    contains module backend Web controller classes
            frontend/   contains module frontend Web controller classes
        messages/       contains i18n module
        models/         contains module-specific model classes
            backend/    contains module backend-specific model classes
            frontend/   contains module frontend-specific model classes
        traits/         contains module traits
        views/          contains module view files for the Web application
            backend/    contains module backend view files for the Web application
            frontend/   contains module frontend view files for the Web application
        Bootstrap.php   File autoload module settings app components (urlManager)
        Module.php      General Module class
    rbac/               contains module rbac
        components/     rules and rbac init
            behavior/   access backend behavior
        console/        contains console controllers (commands)
        controllers/    contains module Web controller classes
            backend/    contains module backend Web controller classes
        messages/       contains i18n module
        migrations/     contains database migrations module
        models/         contains module-specific model classes
        tests/          contains module tests
        traits/         contains module traits
        views/          contains module view files for the Web application
            backend/    contains module backend view files for the Web application
        Bootstrap.php   File autoload module settings app components (urlManager)
        Module.php      General Module class
    users/              contains module users
        behavior/       contains module behavior
        commands/       contains console controllers (commands)
        controllers/    contains module Web controller classes
            backend/    contains module backend Web controller classes
            frontend/   contains module frontend Web controller classes
        mail/           contains module view files for e-mails
        messages/       contains i18n module
        migrations/     contains database migrations module
        models/         contains module-specific model classes
            backend/    contains module backend-specific model classes
            frontend/   contains module frontend-specific model classes
        traits/         contains module traits
        views/          contains module view files for the Web application
            ajax/       contains module ajax.js
            backend/    contains module backend view files for the Web application
            frontend/   contains module frontend view files for the Web application
        widgets/        contains module widgets
        Bootstrap.php   File autoload module settings app components (urlManager)
        Module.php      General Module class

Installation

The preferred way to install this project is through composer., (*11)

Create a project:, (*12)

composer create-project --prefer-dist --stability=dev dominus77/yii2-advanced-start public_html

or clone the repository for pull command availability:, (*13)

git clone https://github.com/Dominus77/yii2-advanced-start.git public_html
cd public_html
composer install

Init an environment:, (*14)

Run command in the root directory public_html of the project, (*15)

if Development environment, (*16)

composer app-init-dev

if Production environment, (*17)

composer app-init-prod

otherwise choose Wednesday, (*18)

php init

Yii Application Requirement Checker

See http://sitename.com/requirements.php, (*19)

Note: For production environment it is recommended to delete the frontend\web\requirements.php file, (*20)

If everything is in order, move on, otherwise configure the server configuration., (*21)

Continue

Create a database, default configure yii2_advanced_start in common\config\main-local.php, (*22)

$config = [
    //...
    'components' => [
        'db' => [
            'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_start',
            //...
        ],
        //...
    ],
    //...
];

Apply migration:, (*23)

composer migrate-up

Initialization RBAC:, (*24)

composer rbac-init

Create user, enter the command and follow the instructions:, (*25)

php yii users/user/create
  • Username: set username (admin);
  • Email: set email (admin@example.com);
  • Password: set password (min 6 symbol);
  • Status: set status (0 - blocked, 1 - active, 2 - wait, ? - Help);

Assign role admin:, (*26)

php yii rbac/roles/assign
  • Username: set username (admin);
  • Role: set role (admin, editor, manager, super_admin, user, ? - Help); (This set configure rbac module models Role.php, Permission.php and in folder components to RbacInit.php)

If you are installing the server into the public_html folder on the server with Apache, you must configure redirection. At the root folder, create a public_html .hitaccess with the following content:, (*27)

Options FollowSymLinks
AddDefaultCharset utf-8

<IfModule mod_rewrite.c>
    RewriteEngine On

    # the main rewrite rule for the frontend application
    RewriteCond %{REQUEST_URI} !^/(backend/web|admin)
    RewriteCond %{REQUEST_URI} !^/(api/web|api)
    RewriteRule !^frontend/web /frontend/web%{REQUEST_URI} [L]

    # redirect to the page without a trailing slash (uncomment if necessary)
    #RewriteCond %{REQUEST_URI} ^/admin/$
    #RewriteRule ^(admin)/ /$1 [L,R=301]
    # the main rewrite rule for the backend application
    RewriteCond %{REQUEST_URI} ^/admin
    RewriteRule ^admin(.*) /backend/web/$1 [L]

    # redirect to the page without a trailing slash (uncomment if necessary)
    #RewriteCond %{REQUEST_URI} ^/api/$
    #RewriteRule ^(api)/ /$1 [L,R=301]
    # the main rewrite rule for the api application
    RewriteCond %{REQUEST_URI} ^/api
    RewriteRule ^api(.*) /api/web/$1 [L]

    # if a directory or a file of the frontend application exists, use the request directly
    RewriteCond %{REQUEST_URI} ^/frontend/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # otherwise forward the request to index.php
    RewriteRule . /frontend/web/index.php [L]

    # if a directory or a file of the backend application exists, use the request directly
    RewriteCond %{REQUEST_URI} ^/backend/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # otherwise forward the request to index.php
    RewriteRule . /backend/web/index.php [L]

    # if a directory or a file of the api application exists, use the request directly
    RewriteCond %{REQUEST_URI} ^/api/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # otherwise forward the request to index.php
    RewriteRule . /api/web/index.php [L]

    RewriteCond %{REQUEST_URI} \.(htaccess|htpasswd|svn|git)
    RewriteRule \.(htaccess|htpasswd|svn|git) - [F]
</IfModule>

The web folder, the backend, frontend and api parts also add .hitaccess:, (*28)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Now frontend is available at http://sitename.com, and backend at http://sitename.com/admin, and api http://sitename.com/api/v1/users, (*29)

Code Sniffer

composer check-style

Testing

Create a database, default configure yii2_advanced_start_test in common\config\test-local.php, (*30)

$config = [
    //...
    'components' => [
        'db' => [
            'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_start_test',
            //...
        ],
        //...
    ],
    //...
];

Apply migration:, (*31)

composer migrate-test-up

Run in console

composer build
composer test

License

The BSD License (BSD). Please see License File for more information., (*32)

The Versions