Skip to content

Commit 3f5e923

Browse files
committed
项目初始化
0 parents  commit 3f5e923

File tree

170 files changed

+7614
-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.

170 files changed

+7614
-0
lines changed

Diff for: .bowerrc

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

Diff for: .gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# yii console commands
2+
/yii
3+
/yii_test
4+
/yii_test.bat
5+
6+
# phpstorm project files
7+
.idea
8+
9+
# netbeans project files
10+
nbproject
11+
12+
# zend studio for eclipse project files
13+
.buildpath
14+
.project
15+
.settings
16+
17+
# windows thumbnail cache
18+
Thumbs.db
19+
20+
# composer vendor dir
21+
/vendor
22+
23+
# composer itself is not needed
24+
composer.phar
25+
26+
# Mac DS_Store Files
27+
.DS_Store
28+
29+
# phpunit itself is not needed
30+
phpunit.phar
31+
# local phpunit config
32+
/phpunit.xml
33+
34+
# vagrant runtime
35+
/.vagrant

Diff for: LICENSE.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
The Yii framework is free software. It is released under the terms of
2+
the following BSD License.
3+
4+
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
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.

Diff for: README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Yii 2 Advanced Project Template
2+
===============================
3+
4+
Yii 2 Advanced Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
5+
developing complex Web applications with multiple tiers.
6+
7+
The template includes three tiers: front end, back end, and console, each of which
8+
is a separate Yii application.
9+
10+
The template is designed to work in a team development environment. It supports
11+
deploying the application in different environments.
12+
13+
Documentation is at [docs/guide/README.md](docs/guide/README.md).
14+
15+
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-app-advanced/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-app-advanced)
16+
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-app-advanced/downloads.png)](https://packagist.org/packages/yiisoft/yii2-app-advanced)
17+
[![Build Status](https://travis-ci.org/yiisoft/yii2-app-advanced.svg?branch=master)](https://travis-ci.org/yiisoft/yii2-app-advanced)
18+
19+
DIRECTORY STRUCTURE
20+
-------------------
21+
22+
```
23+
common
24+
config/ contains shared configurations
25+
mail/ contains view files for e-mails
26+
models/ contains model classes used in both backend and frontend
27+
tests/ contains tests for common classes
28+
console
29+
config/ contains console configurations
30+
controllers/ contains console controllers (commands)
31+
migrations/ contains database migrations
32+
models/ contains console-specific model classes
33+
runtime/ contains files generated during runtime
34+
backend
35+
assets/ contains application assets such as JavaScript and CSS
36+
config/ contains backend configurations
37+
controllers/ contains Web controller classes
38+
models/ contains backend-specific model classes
39+
runtime/ contains files generated during runtime
40+
tests/ contains tests for backend application
41+
views/ contains view files for the Web application
42+
web/ contains the entry script and Web resources
43+
frontend
44+
assets/ contains application assets such as JavaScript and CSS
45+
config/ contains frontend configurations
46+
controllers/ contains Web controller classes
47+
models/ contains frontend-specific model classes
48+
runtime/ contains files generated during runtime
49+
tests/ contains tests for frontend application
50+
views/ contains view files for the Web application
51+
web/ contains the entry script and Web resources
52+
widgets/ contains frontend widgets
53+
vendor/ contains dependent 3rd-party packages
54+
environments/ contains environment-based overrides
55+
```

Diff for: Vagrantfile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require 'yaml'
2+
require 'fileutils'
3+
4+
domains = {
5+
frontend: 'y2aa-frontend.dev',
6+
backend: 'y2aa-backend.dev'
7+
}
8+
9+
config = {
10+
local: './vagrant/config/vagrant-local.yml',
11+
example: './vagrant/config/vagrant-local.example.yml'
12+
}
13+
14+
# copy config from example if local config not exists
15+
FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
16+
# read config
17+
options = YAML.load_file config[:local]
18+
19+
# check github token
20+
if options['github_token'].nil? || options['github_token'].to_s.length != 40
21+
puts "You must place REAL GitHub token into configuration:\n/yii2-app-advanced/vagrant/config/vagrant-local.yml"
22+
exit
23+
end
24+
25+
# vagrant configurate
26+
Vagrant.configure(2) do |config|
27+
# select the box
28+
config.vm.box = 'bento/ubuntu-16.04'
29+
30+
# should we ask about box updates?
31+
config.vm.box_check_update = options['box_check_update']
32+
33+
config.vm.provider 'virtualbox' do |vb|
34+
# machine cpus count
35+
vb.cpus = options['cpus']
36+
# machine memory size
37+
vb.memory = options['memory']
38+
# machine name (for VirtualBox UI)
39+
vb.name = options['machine_name']
40+
end
41+
42+
# machine name (for vagrant console)
43+
config.vm.define options['machine_name']
44+
45+
# machine name (for guest machine console)
46+
config.vm.hostname = options['machine_name']
47+
48+
# network settings
49+
config.vm.network 'private_network', ip: options['ip']
50+
51+
# sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
52+
config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
53+
54+
# disable folder '/vagrant' (guest machine)
55+
config.vm.synced_folder '.', '/vagrant', disabled: true
56+
57+
# hosts settings (host machine)
58+
config.vm.provision :hostmanager
59+
config.hostmanager.enabled = true
60+
config.hostmanager.manage_host = true
61+
config.hostmanager.ignore_private_ip = false
62+
config.hostmanager.include_offline = true
63+
config.hostmanager.aliases = domains.values
64+
65+
# provisioners
66+
config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
67+
config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
68+
config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'
69+
70+
# post-install message (vagrant console)
71+
config.vm.post_up_message = "Frontend URL: http://#{domains[:frontend]}\nBackend URL: http://#{domains[:backend]}"
72+
end

Diff for: backend/assets/AppAsset.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace backend\assets;
4+
5+
use yii\web\AssetBundle;
6+
7+
/**
8+
* Main backend application asset bundle.
9+
*/
10+
class AppAsset extends AssetBundle
11+
{
12+
public $basePath = '@webroot';
13+
public $baseUrl = '@web';
14+
public $css = [
15+
'css/site.css',
16+
];
17+
public $js = [
18+
];
19+
public $depends = [
20+
'yii\web\YiiAsset',
21+
'yii\bootstrap\BootstrapAsset',
22+
];
23+
}

Diff for: backend/codeception.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace: backend\tests
2+
actor: Tester
3+
paths:
4+
tests: tests
5+
log: tests/_output
6+
data: tests/_data
7+
helpers: tests/_support
8+
settings:
9+
bootstrap: _bootstrap.php
10+
colors: true
11+
memory_limit: 1024M
12+
modules:
13+
config:
14+
Yii2:
15+
configFile: 'config/test-local.php'

Diff for: backend/config/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
main-local.php
2+
params-local.php
3+
test-local.php

Diff for: backend/config/bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

Diff for: backend/config/main.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
$params = array_merge(
3+
require(__DIR__ . '/../../common/config/params.php'),
4+
require(__DIR__ . '/../../common/config/params-local.php'),
5+
require(__DIR__ . '/params.php'),
6+
require(__DIR__ . '/params-local.php')
7+
);
8+
9+
return [
10+
'id' => 'app-backend',
11+
'basePath' => dirname(__DIR__),
12+
'controllerNamespace' => 'backend\controllers',
13+
'bootstrap' => ['log'],
14+
'modules' => [],
15+
'components' => [
16+
'request' => [
17+
'csrfParam' => '_csrf-backend',
18+
],
19+
'user' => [
20+
'identityClass' => 'common\models\User',
21+
'enableAutoLogin' => true,
22+
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
23+
],
24+
'session' => [
25+
// this is the name of the session cookie used for login on the backend
26+
'name' => 'advanced-backend',
27+
],
28+
'log' => [
29+
'traceLevel' => YII_DEBUG ? 3 : 0,
30+
'targets' => [
31+
[
32+
'class' => 'yii\log\FileTarget',
33+
'levels' => ['error', 'warning'],
34+
],
35+
],
36+
],
37+
'errorHandler' => [
38+
'errorAction' => 'site/error',
39+
],
40+
41+
'urlManager' => [
42+
'enablePrettyUrl' => true,
43+
'showScriptName' => false,
44+
'rules' => [
45+
],
46+
],
47+
48+
],
49+
'params' => $params,
50+
];

Diff for: backend/config/params.php

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

Diff for: backend/config/test.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return [
3+
'id' => 'app-backend-tests',
4+
'components' => [
5+
'assetManager' => [
6+
'basePath' => __DIR__ . '/../web/assets',
7+
],
8+
'urlManager' => [
9+
'showScriptName' => true,
10+
],
11+
],
12+
];

Diff for: backend/controllers/BrandController.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace backend\controllers;
4+
5+
use backend\models\Brand;
6+
use yii\web\Request;
7+
use yii\web\UploadedFile;
8+
9+
class BrandController extends \yii\web\Controller
10+
{
11+
//添加品牌
12+
public function actionAdd(){
13+
$model = new Brand();
14+
$request = new Request();
15+
if ($request->isPost){
16+
$model->load($request->post());
17+
//实例化文件上传对象
18+
$model->imgFile = UploadedFile::getInstance($model,'imgFile');
19+
//验证数据
20+
if($model->validate()){
21+
//处理图片
22+
//文件上传
23+
if($model->imgFile){
24+
$d = \Yii::getAlias('@webroot').'/upload/'.date('Ymd');
25+
if(!is_dir($d)){
26+
mkdir($d);
27+
}
28+
$fileName = '/upload/'.date('Ymd').'/'.uniqid().'.'.$model->imgFile->extension;
29+
30+
//创建文件夹
31+
$model->imgFile->saveAs(\Yii::getAlias('@webroot').$fileName,false);
32+
$model->logo = $fileName;
33+
}
34+
$model->save(false);
35+
return $this->redirect(['brand/index']);
36+
}else{
37+
//验证失败 打印错误信息
38+
var_dump($model->getErrors());exit;
39+
}
40+
}
41+
return $this->render('add',['model'=>$model]);
42+
}
43+
//展示首页商品列表
44+
public function actionIndex()
45+
{
46+
$brands = Brand::find()->all();
47+
return $this->render('index',['brands'=>$brands]);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)