Skip to content

Commit c1ae24f

Browse files
committed
Initial commit
0 parents  commit c1ae24f

File tree

166 files changed

+5272
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+5272
-0
lines changed

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory" : "vendor/bower"
3+
}

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# environment config
2+
/.env
3+
4+
# phpstorm project files
5+
.idea
6+
7+
# netbeans project files
8+
nbproject
9+
10+
# zend studio for eclipse project files
11+
.buildpath
12+
.project
13+
.settings
14+
15+
# windows thumbnail cache
16+
Thumbs.db
17+
18+
# composer vendor dir
19+
/vendor
20+
21+
# composer itself is not needed
22+
composer.phar
23+
24+
# Mac DS_Store Files
25+
.DS_Store
26+
27+
# phpunit itself is not needed
28+
phpunit.phar
29+
# local phpunit config
30+
/phpunit.xml

LICENSE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
The ninja application template for the Yii framework is free software.
2+
It is released under the terms of the following BSD License.
3+
4+
Copyright © 2015, Alexander Kochetov (https://github.com/creocoder)
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions
9+
are met:
10+
11+
* Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in
15+
the documentation and/or other materials provided with the
16+
distribution.
17+
* Neither the name of Yii Software LLC nor the names of its
18+
contributors may be used to endorse or promote products derived
19+
from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Yii 2 Ninja Application Template
2+
3+
Yii 2 Ninja Application Template is a skeleton Yii 2 application best for
4+
developing complex Web applications with multiple tiers.
5+
6+
The template includes three tiers: frontend, backend and console, each of which
7+
is a separate Yii application.
8+
9+
The template is designed to work in a team development environment. It supports
10+
deploying the application in different environments.
11+
12+
## Installation
13+
14+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
15+
16+
You can then install the application using the following command
17+
18+
```bash
19+
$ php composer.phar global require fxp/composer-asset-plugin
20+
$ php composer.phar create-project --prefer-dist creocoder/yii2-app-ninja
21+
```
22+
23+
## Getting started
24+
25+
After you install the application, you have to conduct the following steps to initialize
26+
the installed application. You only need to do these once for all.
27+
28+
1. Run command `init` to initialize the application with a specific environment.
29+
2. Create a new database and adjust the `.env` configuration file accordingly.
30+
3. Apply migrations with console command `yii migrate`. This will create tables needed for the application to work.
31+
4. Set document roots of your Web server:
32+
33+
- for frontend `/path/to/yii2-app-ninja/frontend/web/` and using the URL `http://frontend/`
34+
- for backend `/path/to/yii2-app-ninja/backend/web/` and using the URL `http://backend/`
35+
36+
To login into the application, you need to first sign up, with any of your email address, username and password.
37+
Then, you can login into the application with same email address and password at any time.
38+
39+
## Directory structure
40+
41+
```
42+
common
43+
config/ contains shared configurations
44+
mail/ contains view files for e-mails
45+
models/ contains model classes used in both backend and frontend
46+
console
47+
config/ contains console configurations
48+
controllers/ contains console controllers (commands)
49+
migrations/ contains database migrations
50+
models/ contains console-specific model classes
51+
runtime/ contains files generated during runtime
52+
backend
53+
assets/ contains application assets such as JavaScript and CSS
54+
config/ contains backend configurations
55+
controllers/ contains Web controller classes
56+
models/ contains backend-specific model classes
57+
runtime/ contains files generated during runtime
58+
views/ contains view files for the Web application
59+
web/ contains the entry script and Web resources
60+
frontend
61+
assets/ contains application assets such as JavaScript and CSS
62+
config/ contains frontend configurations
63+
controllers/ contains Web controller classes
64+
models/ contains frontend-specific model classes
65+
runtime/ contains files generated during runtime
66+
views/ contains view files for the Web application
67+
web/ contains the entry script and Web resources
68+
widgets/ contains frontend widgets
69+
vendor/ contains dependent 3rd-party packages
70+
environments/ contains environment configurations
71+
tests contains various tests for the advanced application
72+
codeception/ contains tests developed with Codeception PHP Testing Framework
73+
```
74+
75+
## Donating
76+
77+
Support this project and [others by creocoder](https://gratipay.com/creocoder/) via [gratipay](https://gratipay.com/creocoder/).
78+
79+
[![Support via Gratipay](https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.svg)](https://gratipay.com/creocoder/)

backend/assets/AppAsset.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @link http://www.yiiframework.com/
4+
* @copyright Copyright (c) 2008 Yii Software LLC
5+
* @license http://www.yiiframework.com/license/
6+
*/
7+
8+
namespace backend\assets;
9+
10+
use yii\web\AssetBundle;
11+
12+
/**
13+
* @author Qiang Xue <[email protected]>
14+
* @since 2.0
15+
*/
16+
class AppAsset extends AssetBundle
17+
{
18+
public $basePath = '@webroot';
19+
public $baseUrl = '@web';
20+
public $css = [
21+
'css/site.css',
22+
];
23+
public $js = [
24+
];
25+
public $depends = [
26+
'yii\web\YiiAsset',
27+
'yii\bootstrap\BootstrapAsset',
28+
];
29+
}

backend/config/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main-local.php
2+
params-local.php

backend/config/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

backend/config/main.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
$params = array_merge(
4+
require(__DIR__ . '/../../common/config/params.php'),
5+
require(__DIR__ . '/params.php')
6+
);
7+
8+
$config = [
9+
'id' => 'app-backend',
10+
'basePath' => __DIR__ . '/..',
11+
'controllerNamespace' => 'backend\controllers',
12+
'bootstrap' => ['log'],
13+
'components' => [
14+
'user' => [
15+
'identityClass' => 'common\models\User',
16+
'enableAutoLogin' => true,
17+
],
18+
'log' => [
19+
'traceLevel' => YII_DEBUG ? 3 : 0,
20+
'targets' => [
21+
[
22+
'class' => 'yii\log\FileTarget',
23+
'levels' => ['error', 'warning'],
24+
],
25+
],
26+
],
27+
'errorHandler' => [
28+
'errorAction' => 'site/error',
29+
],
30+
'request' => [
31+
'cookieValidationKey' => getenv('COOKIE_VALIDATION_KEY'),
32+
],
33+
],
34+
'params' => $params,
35+
];
36+
37+
if (YII_ENV_DEV) {
38+
$config['bootstrap'][] = 'debug';
39+
$config['modules']['debug'] = 'yii\debug\Module';
40+
$config['bootstrap'][] = 'gii';
41+
$config['modules']['gii'] = 'yii\gii\Module';
42+
}
43+
44+
return $config;

backend/config/params.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'adminEmail' => '[email protected]',
5+
];
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
namespace backend\controllers;
3+
4+
use Yii;
5+
use yii\filters\AccessControl;
6+
use yii\web\Controller;
7+
use common\models\LoginForm;
8+
use yii\filters\VerbFilter;
9+
10+
/**
11+
* Site controller
12+
*/
13+
class SiteController extends Controller
14+
{
15+
/**
16+
* @inheritdoc
17+
*/
18+
public function behaviors()
19+
{
20+
return [
21+
'access' => [
22+
'class' => AccessControl::className(),
23+
'rules' => [
24+
[
25+
'actions' => ['login', 'error'],
26+
'allow' => true,
27+
],
28+
[
29+
'actions' => ['logout', 'index'],
30+
'allow' => true,
31+
'roles' => ['@'],
32+
],
33+
],
34+
],
35+
'verbs' => [
36+
'class' => VerbFilter::className(),
37+
'actions' => [
38+
'logout' => ['post'],
39+
],
40+
],
41+
];
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function actions()
48+
{
49+
return [
50+
'error' => [
51+
'class' => 'yii\web\ErrorAction',
52+
],
53+
];
54+
}
55+
56+
public function actionIndex()
57+
{
58+
return $this->render('index');
59+
}
60+
61+
public function actionLogin()
62+
{
63+
if (!\Yii::$app->user->isGuest) {
64+
return $this->goHome();
65+
}
66+
67+
$model = new LoginForm();
68+
if ($model->load(Yii::$app->request->post()) && $model->login()) {
69+
return $this->goBack();
70+
} else {
71+
return $this->render('login', [
72+
'model' => $model,
73+
]);
74+
}
75+
}
76+
77+
public function actionLogout()
78+
{
79+
Yii::$app->user->logout();
80+
81+
return $this->goHome();
82+
}
83+
}

0 commit comments

Comments
 (0)