• Stars
    star
    630
  • Rank 68,511 (Top 2 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Yii 2.0 Basic Application Template

Yii 2 Basic Project Template


Yii 2 Basic Project Template is a skeleton Yii 2 application best for rapidly creating small projects.

The template contains the basic features including user login/logout and a contact page. It includes all commonly used configurations that would allow you to focus on adding new features to your application.

Latest Stable Version Total Downloads build

DIRECTORY STRUCTURE

  assets/             contains assets definition
  commands/           contains console commands (controllers)
  config/             contains application configurations
  controllers/        contains Web controller classes
  mail/               contains view files for e-mails
  models/             contains model classes
  runtime/            contains files generated during runtime
  tests/              contains various tests for the basic application
  vendor/             contains dependent 3rd-party packages
  views/              contains view files for the Web application
  web/                contains the entry script and Web resources

REQUIREMENTS

The minimum requirement by this project template that your Web server supports PHP 7.4.

INSTALLATION

Install via Composer

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

You can then install this project template using the following command:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

Now you should be able to access the application through the following URL, assuming basic is the directory directly under the Web root.

http://localhost/basic/web/

Install from an Archive File

Extract the archive file downloaded from yiiframework.com to a directory named basic that is directly under the Web root.

Set cookie validation key in config/web.php file to some random secret string:

'request' => [
    // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
    'cookieValidationKey' => '<secret random string goes here>',
],

You can then access the application through the following URL:

http://localhost/basic/web/

Install with Docker

Update your vendor packages

docker-compose run --rm php composer update --prefer-dist

Run the installation triggers (creating cookie validation code)

docker-compose run --rm php composer install    

Start the container

docker-compose up -d

You can then access the application through the following URL:

http://127.0.0.1:8000

NOTES:

  • Minimum required Docker engine version 17.04 for development (see Performance tuning for volume mounts)
  • The default configuration uses a host-volume in your home directory .docker-composer for composer caches

CONFIGURATION

Database

Edit the file config/db.php with real data, for example:

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => '1234',
    'charset' => 'utf8',
];

NOTES:

  • Yii won't create the database for you, this has to be done manually before you can access it.
  • Check and edit the other files in the config/ directory to customize your application as required.
  • Refer to the README in the tests directory for information specific to basic application tests.

TESTING

Tests are located in tests directory. They are developed with Codeception PHP Testing Framework. By default, there are 3 test suites:

  • unit
  • functional
  • acceptance

Tests can be executed by running

vendor/bin/codecept run

The command above will execute unit and functional tests. Unit tests are testing the system components, while functional tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since they perform testing in real browser.

Running acceptance tests

To execute acceptance tests do the following:

  1. Rename tests/acceptance.suite.yml.example to tests/acceptance.suite.yml to enable suite configuration

  2. Replace codeception/base package in composer.json with codeception/codeception to install full-featured version of Codeception

  3. Update dependencies with Composer

    composer update  
    
  4. Download Selenium Server and launch it:

    java -jar ~/selenium-server-standalone-x.xx.x.jar
    

    In case of using Selenium Server 3.0 with Firefox browser since v48 or Google Chrome since v53 you must download GeckoDriver or ChromeDriver and launch Selenium with it:

    # for Firefox
    java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar
    
    # for Google Chrome
    java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
    

    As an alternative way you can use already configured Docker container with older versions of Selenium and Firefox:

    docker run --net=host selenium/standalone-firefox:2.53.0
    
  5. (Optional) Create yii2basic_test database and update it by applying migrations if you have them.

    tests/bin/yii migrate
    

    The database configuration can be found at config/test_db.php.

  6. Start web server:

    tests/bin/yii serve
    
  7. Now you can run all available tests

    # run all available tests
    vendor/bin/codecept run
    
    # run acceptance tests
    vendor/bin/codecept run acceptance
    
    # run only unit and functional tests
    vendor/bin/codecept run unit,functional
    

Code coverage support

By default, code coverage is disabled in codeception.yml configuration file, you should uncomment needed rows to be able to collect code coverage. You can run your tests and collect coverage with the following command:

#collect coverage for all tests
vendor/bin/codecept run --coverage --coverage-html --coverage-xml

#collect coverage only for unit tests
vendor/bin/codecept run unit --coverage --coverage-html --coverage-xml

#collect coverage for unit and functional tests
vendor/bin/codecept run functional,unit --coverage --coverage-html --coverage-xml

You can see code coverage output under the tests/_output directory.

More Repositories

1

yii2

Yii 2: The Fast, Secure and Professional PHP Framework
PHP
14,127
star
2

yii

Yii PHP Framework 1.1.x
PHP
4,851
star
3

yii2-app-advanced

Yii 2.0 Advanced Application Template
PHP
1,628
star
4

yii2-queue

Yii2 Queue Extension. Supports DB, Redis, RabbitMQ, Beanstalk and Gearman
PHP
1,065
star
5

yii2-authclient

Yii 2 authclient extension.
PHP
455
star
6

yii2-redis

Yii 2 Redis extension.
PHP
444
star
7

yii-core

Yii Framework 3.0 core
433
star
8

yii2-elasticsearch

Yii 2 Elasticsearch extension
PHP
428
star
9

yii2-httpclient

Yii 2 HTTP client
PHP
422
star
10

yii2-docker

Official Docker images suitable for Yii 2.0
PHP
363
star
11

yii2-mongodb

Yii 2 MongoDB extension
PHP
318
star
12

demo

Yii 3 demo application
PHP
309
star
13

yii2-imagine

Yii 2 imagine extension
PHP
282
star
14

yii2-apidoc

Yii 2 apidoc extension.
PHP
254
star
15

yii2-framework

[READ ONLY] Yii 2 framework core code only. This is a subtree split off the "yii2" repository
PHP
232
star
16

docs

Various Yii 3.0 related documentation
226
star
17

app

Yii3 application template
PHP
214
star
18

yii2-bootstrap4

Yii 2 Bootstrap 4 Extension
PHP
210
star
19

yii2-gii

Yii 2 Gii Extension
PHP
198
star
20

yii2-debug

Debug Extension for Yii 2
PHP
195
star
21

yii2-bootstrap

Yii 2 Bootstrap 3 Extension
PHP
183
star
22

yii2-coding-standards

Yii 2 coding standards
PHP
179
star
23

yii2-sphinx

Yii 2 Sphinx extension.
PHP
179
star
24

di

PSR-11 compatible DI container and injector
PHP
168
star
25

yii2-shell

Interactive shell
PHP
138
star
26

yii2-twig

Yii 2 Twig extension.
PHP
136
star
27

yii2-jui

Yii 2 JQuery UI extension.
PHP
125
star
28

db

Yii Database Library
PHP
123
star
29

yii-project-template

PHP
120
star
30

yii2-swiftmailer

Yii 2 swiftmailer extension.
PHP
114
star
31

yii2-faker

Yii 2 Faker extension
PHP
104
star
32

validator

Yii validator library
PHP
103
star
33

yii-base-web

PHP
101
star
34

yii-api

Yii REST API framework
PHP
92
star
35

yii2-composer

Yii 2 composer extension
PHP
81
star
36

yii-web

Yii web components
PHP
78
star
37

yii2-smarty

Yii 2 Smarty Extension.
PHP
72
star
38

event-dispatcher

PSR-14 event dispatcher
PHP
66
star
39

yii-dev-tool

Development environment for Yii 3 packages
PHP
65
star
40

yii-console

Yii console components
PHP
62
star
41

active-record

Active Record database abstraction layer
PHP
62
star
42

yii2-collection

Collection extension for Yii 2
PHP
62
star
43

rbac

Role based access control
PHP
59
star
44

router

Router is a request matcher and URL generator
PHP
58
star
45

yii2-bootstrap5

Yii 2 Bootstrap 5 Extension
PHP
58
star
46

app-api

API application project template
PHP
56
star
47

yii-bootstrap5

Yii Framework Bootstrap 5 support
PHP
56
star
48

yii2-codeception

Yii 2 Codeception extension (DEPRECATED)
PHP
54
star
49

view

Yii view rendering library
PHP
54
star
50

queue

Queue extension for Yii 3.0
PHP
54
star
51

yii-base-api

REST API application template
PHP
52
star
52

html

Handy library to generate HTML
PHP
51
star
53

arrays

Yii Array Helper
PHP
48
star
54

friendly-exception

An interface for an exception to be friendly
PHP
47
star
55

strings

String helper methods and an inflector
PHP
45
star
56

security

A set of classes to handle common security-related tasks
PHP
42
star
57

yii-cycle

Cycle ORM support for Yii
PHP
41
star
58

yii-docker

Official Docker images suitable for Yii 3.0+
PHP
41
star
59

router-fastroute

Yii Router FastRoute adapter
PHP
39
star
60

data

Data providers
PHP
39
star
61

injector

PSR-11 compatible injector
PHP
38
star
62

yii-masked-input

Yii Framework Masked input widget Extension
PHP
38
star
63

yii2-symfonymailer

Yii 2 Symfony mailer extension.
PHP
38
star
64

yii-dataview

Data widgets
PHP
36
star
65

form

The package helps with implementing data entry forms
PHP
36
star
66

db-mysql

MySQL and MariaDB driver for Yii Database
PHP
35
star
67

log

PSR-3 compatible logger
PHP
35
star
68

auth

PHP
33
star
69

mutex

Mutex lock implementation
PHP
32
star
70

files

Useful methods to manage files and directories
PHP
32
star
71

package-template

A template for a new package within yiisoft
PHP
32
star
72

factory

Object factory that is able to resolve dependencies from PSR-11 container
PHP
32
star
73

composer-config-plugin

Composer plugin for config assembling
PHP
31
star
74

yii-gii

Yii code generator extension
PHP
31
star
75

cache

PSR-16 compatible cache library
PHP
31
star
76

auth-jwt

PHP
31
star
77

config

Configuration management
PHP
30
star
78

access

Access checking abstraction
PHP
29
star
79

db-pgsql

PostgreSQL driver for Yii Database
PHP
28
star
80

demo-api

PHP
28
star
81

yii-debug

Yii debug panel extension
PHP
27
star
82

yii-runner-roadrunner

Web application runner for RoadRunner
PHP
27
star
83

db-migration

The package implementing migration for yiisoft/db.
PHP
27
star
84

network-utilities

Network related utilities
PHP
26
star
85

yii-jquery

Yii Framework jQuery Extension
JavaScript
26
star
86

rate-limiter

RateLimiter helps to prevent abuse by limiting the number of requests that could be me made consequentially.
PHP
26
star
87

yii-base-cli

Yii Framework Command Line Application
PHP
26
star
88

json

JSON encoding and decoding
PHP
25
star
89

yii-swagger

Swagger integration for Yii
PHP
25
star
90

db-oracle

Oracle driver for Yii Database
PHP
25
star
91

db-sqlite

SQLite driver for Yii Database
PHP
25
star
92

http

Handy HTTP utility such as method constants and status codes
PHP
25
star
93

view-twig

Yii View Twig Renderer
PHP
24
star
94

i18n

Yii i18n
PHP
24
star
95

yii-bulma

Yii Framework Bulma Integration
PHP
24
star
96

widget

Widgets are reusable building blocks used to create complex and configurable user interface elements in an object-oriented fashion
PHP
24
star
97

aliases

Named paths and URLs storage
PHP
23
star
98

yii-auth-client

Yii Framework external authentication via OAuth and OpenID Extension
PHP
23
star
99

yii-bootstrap4

Yii Framework Bootstrap 4 support
PHP
23
star
100

csrf

PSR-15 middleware implementing CSRF protection
PHP
22
star