Adjusted Yii2 Application Template
This is the Yii2 Advanced Template adjusted to be more convenient and usable., (*1)
You can now:, (*2)
-
Run your app without any Apache2 configuration.
You will still need mod_rewrite enabled but do not need to configure virtual
hosts or setup multiple Document Roots., (*3)
-
You can run your app in a subdirectory of your Apache Document Root, (*4)
-
Backend can be reached by going to /admin. However you will need to create
a symbolic link by doing the following:
cd /path/to/app
ln -s backend/web admin, (*5)
-
Pretty URLs have been enabled on front end and back end, (*6)
-
Separate sessions and cookies for front end and back end, to avoid collisions, (*7)
Installation
Install With Composer
The preferred way to install this extension is through composer., (*8)
Make sure you have this globally installed:, (*9)
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta4"
Now you can navigate to your web server's Document Root and create a new project and put it into a sub-folder called advanced:, (*10)
php composer.phar create-project --prefer-dist --stability=dev stancel/yii2_advanced_template_adjusted advanced
Next, you need to initialize this Yii2 instance by running:, (*11)
cd /to/your/application/path/advanced/
php init
and follow the prompts to choose if you are going to setup a Development or Production instance., (*12)
Create a symbolic link from the root application directory to the backend web folder so you can later the backend as http://localhost/advanced/admin:, (*13)
cd /to/your/application/path/advanced/
ln -s backend/web admin
Next you will go into the common/config/main-local.php file and enter your database details here:, (*14)
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=YOUR_DB_NAME_HERE',
'username' => 'YOUR_DB_USERNAME_HERE',
'password' => 'YOUR_DB_PASSWORD_HERE',
'charset' => 'utf8',
],
Once that is completed and saved, your final step is run the yii migration tool:, (*15)
cd /to/your/application/path/yii2_advanced_template_adjusted/
php yii migrate
Now you can use the Gii tool to generate your a CRUD scaffolding (Models, View and Controllers) by navigating to:, (*16)
http://localhost/advanced/gii
Yii 2 Advanced Application Template
Yii 2 Advanced Application Template is a skeleton Yii 2 application best for
developing complex Web applications with multiple tiers., (*17)
The template includes three tiers: front end, back end, and console, each of which
is a separate Yii application., (*18)
The template is designed to work in a team development environment. It supports
deploying the application in different environments., (*19)
DIRECTORY STRUCTURE
common
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
console
config/ contains console configurations
controllers/ contains console controllers (commands)
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
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
views/ contains view files for the Web application
web/ contains the entry script and Web resources
frontend
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
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
tests contains various tests for the advanced application
codeception/ contains tests developed with Codeception PHP Testing Framework
REQUIREMENTS
The minimum requirement by this application template that your Web server supports PHP 5.4.0., (*20)
INSTALLATION
Install from an Archive File
Extract the archive file downloaded from yiiframework.com to
a directory named advanced
that is directly under the Web root., (*21)
Then follow the instructions given in "GETTING STARTED"., (*22)
Install via Composer
If you do not have Composer, you may install it by following the instructions
at getcomposer.org., (*23)
You can then install the application using the following command:, (*24)
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta4"
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced advanced
GETTING STARTED
After you install the application, you have to conduct the following steps to initialize
the installed application. You only need to do these once for all., (*25)
- Run command
init
to initialize the application with a specific environment.
- Create a new database and adjust the
components['db']
configuration in common/config/main-local.php
accordingly.
- Apply migrations with console command
yii migrate
. This will create tables needed for the application to work.
- Set document roots of your Web server:
- for frontend
/path/to/yii-application/frontend/web/
and using the URL http://frontend/
- for backend
/path/to/yii-application/backend/web/
and using the URL http://backend/
To login into the application, you need to first sign up, with any of your email address, username and password.
Then, you can login into the application with same email address and password at any time., (*26)