Skip to content

Commit 2b32e62

Browse files
committed
add asset
1 parent f89aa73 commit 2b32e62

17 files changed

+354
-2
lines changed

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DB_HOST=localhost
2+
DB_NAME=dbname
3+
DB_USER=user
4+
DB_PASS=password
5+
YII_DEBUG=true
6+
YII_ENV=dev
7+
YII_MAIL_USE_FILE_TRANSPORT=true

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ composer.phar
2525
phpunit.phar
2626
# local phpunit config
2727
/phpunit.xml
28+
29+
30+
# env vars
31+
.env

composer.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
"yiisoft/yii2": ">=2.0.4",
1818
"yiisoft/yii2-bootstrap": "*",
1919
"yiisoft/yii2-swiftmailer": "*",
20-
"vlucas/phpdotenv": "~1.0@dev"
20+
"vlucas/phpdotenv": "~1.0@dev",
21+
"nullref/yii2-useful": "dev-master",
22+
"nullref/yii2-core": "dev-master",
23+
"nullref/yii2-product": "dev-master",
24+
"composer/composer": "~1.0@dev",
25+
"bower-asset/startbootstrap-sb-admin-2": "dev-master"
2126
},
2227
"require-dev": {
2328
"yiisoft/yii2-codeception": "*",
@@ -51,4 +56,4 @@
5156
"bower-asset-library": "vendor/bower"
5257
}
5358
}
54-
}
59+
}

src/assets/AppAsset.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 app\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/main.css',
22+
'css/site.css',
23+
];
24+
public $js = [
25+
'js/tools.js',
26+
'js/scripts.js',
27+
];
28+
public $depends = [
29+
'yii\web\YiiAsset',
30+
];
31+
}

src/config/console.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
//@TODO
5+
];

src/config/db.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'class' => 'yii\db\Connection',
5+
'dsn' => 'mysql:host='.getenv('DB_HOST').';dbname=' . getenv('DB_NAME'),
6+
'username' => getenv('DB_USER'),
7+
'password' => getenv('DB_PASS'),
8+
'charset' => 'utf8',
9+
];

src/config/modules.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'core' => ['class' => 'nullref\core\Module'],
5+
6+
];

src/config/params.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'adminEmail' => '[email protected]',
5+
];

src/config/web.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
$params = require(__DIR__ . '/params.php');
4+
$modules = require(__DIR__ . '/modules.php');
5+
6+
$config = [
7+
'id' => 'app',
8+
'name' => 'Application',
9+
'basePath' => dirname(__DIR__),
10+
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
11+
'runtimePath' => dirname(dirname(__DIR__)) . '/runtime',
12+
'bootstrap' => ['log', 'core'],
13+
'components' => [
14+
'formatter' => [
15+
'class' => 'app\components\Formatter',
16+
],
17+
'request' => [
18+
'cookieValidationKey' => 'RiAveGUdUACvWZppHVevMJRGd5Rij8uh',
19+
],
20+
'cache' => [
21+
'class' => 'yii\caching\FileCache',
22+
],
23+
'user' => [
24+
'identityClass' => 'app\models\User',
25+
'enableAutoLogin' => true,
26+
],
27+
'errorHandler' => [
28+
'errorAction' => 'site/error',
29+
],
30+
'mailer' => [
31+
'class' => 'yii\swiftmailer\Mailer',
32+
'useFileTransport' => YII_ENV_DEV,
33+
],
34+
'i18n' => [
35+
'translations' => [
36+
'*' => ['class' => 'yii\i18n\PhpMessageSource'],
37+
],
38+
],
39+
'log' => [
40+
'traceLevel' => YII_DEBUG ? 3 : 0,
41+
'targets' => [
42+
[
43+
'class' => 'yii\log\FileTarget',
44+
'levels' => ['error', 'warning'],
45+
],
46+
],
47+
],
48+
'urlManager' => [
49+
'enablePrettyUrl' => true,
50+
'showScriptName' => false,
51+
],
52+
'db' => require(__DIR__ . '/db.php'),
53+
],
54+
'modules' => $modules,
55+
'params' => $params,
56+
];
57+
58+
if (YII_ENV_DEV) {
59+
// configuration adjustments for 'dev' environment
60+
$config['bootstrap'][] = 'debug';
61+
$config['modules']['debug'] = 'yii\debug\Module';
62+
63+
$config['bootstrap'][] = 'gii';
64+
$config['modules']['gii'] = 'yii\gii\Module';
65+
}
66+
67+
return $config;

src/controllers/SiteController.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
use Yii;
6+
use yii\filters\VerbFilter;
7+
use yii\web\Controller;
8+
9+
10+
class SiteController extends Controller
11+
{
12+
public function behaviors()
13+
{
14+
return [
15+
'verbs' => [
16+
'class' => VerbFilter::className(),
17+
'actions' => [
18+
'logout' => ['post'],
19+
],
20+
],
21+
];
22+
}
23+
24+
public function actions()
25+
{
26+
return [
27+
'error' => [
28+
'class' => 'yii\web\ErrorAction',
29+
],
30+
'captcha' => [
31+
'class' => 'yii\captcha\CaptchaAction',
32+
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
33+
],
34+
];
35+
}
36+
37+
public function actionIndex()
38+
{
39+
return $this->render('index');
40+
}
41+
}

src/views/layouts/main.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
use app\assets\AppAsset;
3+
use yii\bootstrap\Nav;
4+
use yii\bootstrap\NavBar;
5+
use yii\helpers\Html;
6+
use yii\widgets\Breadcrumbs;
7+
8+
/* @var $this \yii\web\View */
9+
/* @var $content string */
10+
11+
AppAsset::register($this);
12+
?>
13+
<?php $this->beginPage() ?>
14+
<!DOCTYPE html>
15+
<html lang="<?= Yii::$app->language ?>">
16+
<head>
17+
<meta charset="<?= Yii::$app->charset ?>">
18+
<meta name="viewport" content="width=device-width, initial-scale=1">
19+
<?= Html::csrfMetaTags() ?>
20+
<title><?= Html::encode($this->title) ?></title>
21+
<?php $this->head() ?>
22+
</head>
23+
<body>
24+
25+
<?php $this->beginBody() ?>
26+
<div class="wrap">
27+
<?php
28+
NavBar::begin([
29+
'brandLabel' => Yii::$app->name,
30+
'brandUrl' => Yii::$app->homeUrl,
31+
'options' => [
32+
'class' => 'navbar-inverse',
33+
],
34+
]);
35+
echo Nav::widget([
36+
'encodeLabels' => false,
37+
'options' => ['class' => 'navbar-nav navbar-right'],
38+
'items' => [
39+
['label' => Yii::t('app', 'Home'), 'url' => ['/site/index']],
40+
],
41+
]);
42+
NavBar::end();
43+
?>
44+
45+
<div class="container">
46+
<?= Breadcrumbs::widget([
47+
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
48+
]) ?>
49+
50+
<?php foreach (Yii::$app->session->getAllFlashes() as $type => $text): ?>
51+
52+
<div class="alert alert-<?= $type ?>">
53+
<?= $text ?>
54+
</div>
55+
56+
<?php endforeach; ?>
57+
<?= $content ?>
58+
</div>
59+
</div>
60+
61+
<footer class="footer">
62+
<div class="container">
63+
<p class="pull-left">&copy; NRE <?= date('Y') ?></p>
64+
65+
<p class="pull-right"><?= Yii::powered() ?></p>
66+
</div>
67+
</footer>
68+
69+
<?php $this->endBody() ?>
70+
</body>
71+
</html>
72+
<?php $this->endPage() ?>

src/views/site/error.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use yii\helpers\Html;
4+
5+
/* @var $this yii\web\View */
6+
/* @var $name string */
7+
/* @var $message string */
8+
/* @var $exception Exception */
9+
10+
$this->title = $name;
11+
?>
12+
<div class="site-error">
13+
14+
<h1><?= Html::encode($this->title) ?></h1>
15+
16+
<div class="alert alert-danger">
17+
<?= nl2br(Html::encode($message)) ?>
18+
</div>
19+
20+
21+
</div>

src/views/site/index.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/* @var $this yii\web\View */
4+
$this->title = Yii::$app->name;
5+
?>
6+
<div class="site-index">
7+
<h1>Hello world</h1>
8+
<pre>
9+
</pre>
10+
</div>

web/css/site.css

Whitespace-only changes.

web/index.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
require(__DIR__ . '/../vendor/autoload.php');
4+
5+
Dotenv::load(__DIR__ . '/..');
6+
Dotenv::required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'YII_DEBUG', 'YII_MAIL_USE_FILE_TRANSPORT']);
7+
8+
defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG') != 'false');
9+
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
10+
defined('YII_MAIL_USE_FILE_TRANSPORT') or define('YII_MAIL_USE_FILE_TRANSPORT', getenv('YII_MAIL_USE_FILE_TRANSPORT') == 'true');
11+
12+
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
13+
14+
$config = require(__DIR__ . '/../src/config/web.php');
15+
(new yii\web\Application($config))->run();

web/js/scripts.js

Whitespace-only changes.

web/js/tools.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @section useful functions to types
3+
*/
4+
(function () {
5+
String.prototype.addUrlParam = function (key, value) {
6+
return tools.addUrlParam(this, key, value);
7+
};
8+
String.prototype.format = function (map) {
9+
var newValue = this, key, value, i, index, arg;
10+
for (i = 0; i < arguments.length; i++) {
11+
arg = arguments[i];
12+
if (tools.isObject(arg)) {
13+
for (index in arg) {
14+
if (arg.hasOwnProperty(index)) {
15+
value = arg[index];
16+
key = '{' + index + '}';
17+
newValue = newValue.replace(new RegExp(key, 'g'), value);
18+
}
19+
}
20+
} else {
21+
key = '{' + i + '\\}';
22+
newValue = newValue.replace(new RegExp(key, 'g'), arg);
23+
}
24+
}
25+
return newValue;
26+
};
27+
})();
28+
/**
29+
* @section tools object
30+
*/
31+
var tools = {
32+
isString: function (obj) {
33+
return typeof obj === 'string';
34+
},
35+
isObject: function (obj) {
36+
return typeof obj === 'object';
37+
},
38+
isNumber: function (obj) {
39+
return typeof obj === 'number';
40+
},
41+
isUndefined: function (value) {
42+
return typeof value === 'undefined';
43+
},
44+
isDefined: function (value) {
45+
return typeof value !== 'undefined';
46+
},
47+
addUrlParam: function (base, key, value) {
48+
if (base && key && value) {
49+
var sep = (base.indexOf('?') > -1) ? '&' : '?';
50+
return base + sep + key + '=' + value;
51+
}
52+
return base;
53+
}
54+
};

0 commit comments

Comments
 (0)