Skip to content

Commit 29ce614

Browse files
committed
yii2 add hook
1 parent 342646e commit 29ce614

File tree

4,289 files changed

+1065447
-1
lines changed

Some content is hidden

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

4,289 files changed

+1065447
-1
lines changed

LICENSE.md

Lines changed: 32 additions & 0 deletions
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.

README.md

100644100755
Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# yii2_hook_demo
1+
Yii 2 Basic Project Template
2+
============================
3+
4+
Yii 2 Basic Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
5+
rapidly creating small projects.
6+
7+
The template contains the basic features including user login/logout and a contact page.
8+
It includes all commonly used configurations that would allow you to focus on adding new
9+
features to your application.
10+
11+
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-app-basic/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-app-basic)
12+
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-app-basic/downloads.png)](https://packagist.org/packages/yiisoft/yii2-app-basic)
13+
[![Build Status](https://travis-ci.org/yiisoft/yii2-app-basic.svg?branch=master)](https://travis-ci.org/yiisoft/yii2-app-basic)
14+
15+
DIRECTORY STRUCTURE
16+
-------------------
17+
18+
assets/ contains assets definition
19+
commands/ contains console commands (controllers)
20+
config/ contains application configurations
21+
controllers/ contains Web controller classes
22+
mail/ contains view files for e-mails
23+
models/ contains model classes
24+
runtime/ contains files generated during runtime
25+
tests/ contains various tests for the basic application
26+
vendor/ contains dependent 3rd-party packages
27+
views/ contains view files for the Web application
28+
web/ contains the entry script and Web resources
29+
30+
31+
32+
REQUIREMENTS
33+
------------
34+
35+
The minimum requirement by this project template that your Web server supports PHP 5.4.0.
36+
37+
38+
INSTALLATION
39+
------------
40+
41+
### Install from an Archive File
42+
43+
Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
44+
a directory named `basic` that is directly under the Web root.
45+
46+
Set cookie validation key in `config/web.php` file to some random secret string:
47+
48+
```php
49+
'request' => [
50+
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
51+
'cookieValidationKey' => '<secret random string goes here>',
52+
],
53+
```
54+
55+
You can then access the application through the following URL:
56+
57+
~~~
58+
http://localhost/basic/web/
59+
~~~
60+
61+
62+
### Install via Composer
63+
64+
If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
65+
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
66+
67+
You can then install this project template using the following command:
68+
69+
~~~
70+
php composer.phar global require "fxp/composer-asset-plugin:~1.1.1"
71+
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
72+
~~~
73+
74+
Now you should be able to access the application through the following URL, assuming `basic` is the directory
75+
directly under the Web root.
76+
77+
~~~
78+
http://localhost/basic/web/
79+
~~~
80+
81+
82+
CONFIGURATION
83+
-------------
84+
85+
### Database
86+
87+
Edit the file `config/db.php` with real data, for example:
88+
89+
```php
90+
return [
91+
'class' => 'yii\db\Connection',
92+
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
93+
'username' => 'root',
94+
'password' => '1234',
95+
'charset' => 'utf8',
96+
];
97+
```
98+
99+
**NOTES:**
100+
- Yii won't create the database for you, this has to be done manually before you can access it.
101+
- Check and edit the other files in the `config/` directory to customize your application as required.
102+
- Refer to the README in the `tests` directory for information specific to basic application tests.

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 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/site.css',
22+
];
23+
public $js = [
24+
];
25+
public $depends = [
26+
'yii\web\YiiAsset',
27+
'yii\bootstrap\BootstrapAsset',
28+
];
29+
}

commands/HelloController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\commands;
9+
10+
use yii\console\Controller;
11+
12+
/**
13+
* This command echoes the first argument that you have entered.
14+
*
15+
* This command is provided as an example for you to learn how to create console commands.
16+
*
17+
* @author Qiang Xue <[email protected]>
18+
* @since 2.0
19+
*/
20+
class HelloController extends Controller
21+
{
22+
/**
23+
* This command echoes what you have entered as the message.
24+
* @param string $message the message to be echoed.
25+
*/
26+
public function actionIndex($message = 'hello world')
27+
{
28+
echo $message . "\n";
29+
}
30+
}

components/Hook.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* HOOK
4+
*
5+
* @author Sun <[email protected]>
6+
* @copyright http://www.wstaichi.com
7+
* @time 2016
8+
*/
9+
namespace app\components;
10+
11+
12+
class Hook
13+
{
14+
static $obj = [];
15+
static $value;
16+
17+
static function listen($name,&$arg = array() ){
18+
19+
$hook = self::$obj[$name];
20+
if($hook){
21+
foreach($hook as $call){
22+
$obj = $call['obj'];
23+
$method = $call['method'];
24+
$obj->$method($arg);
25+
26+
}
27+
}
28+
}
29+
static function value($name,$value = null){
30+
if(!$value){
31+
return self::$value[$name];
32+
}
33+
self::$value[$name] = $value;
34+
}
35+
36+
static function add($name,$obj,$method){
37+
self::$obj[$name][] = ['obj'=>$obj,'method'=>$method];
38+
}
39+
}

composer.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "yiisoft/yii2-app-basic",
3+
"description": "Yii 2 Basic Project Template",
4+
"keywords": ["yii2", "framework", "basic", "project template"],
5+
"homepage": "http://www.yiiframework.com/",
6+
"type": "project",
7+
"license": "BSD-3-Clause",
8+
"support": {
9+
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
10+
"forum": "http://www.yiiframework.com/forum/",
11+
"wiki": "http://www.yiiframework.com/wiki/",
12+
"irc": "irc://irc.freenode.net/yii",
13+
"source": "https://github.com/yiisoft/yii2"
14+
},
15+
"minimum-stability": "stable",
16+
"require": {
17+
"php": ">=5.4.0",
18+
"yiisoft/yii2": ">=2.0.5",
19+
"yiisoft/yii2-bootstrap": "*",
20+
"yiisoft/yii2-swiftmailer": "*",
21+
"yiisoft/yii2-mongodb": "^2.1",
22+
"yiisoft/yii2-apidoc": "^2.0"
23+
},
24+
"require-dev": {
25+
"yiisoft/yii2-codeception": "*",
26+
"yiisoft/yii2-debug": "*",
27+
"yiisoft/yii2-gii": "*",
28+
"yiisoft/yii2-faker": "*"
29+
},
30+
"config": {
31+
"process-timeout": 1800
32+
},
33+
"scripts": {
34+
"post-create-project-cmd": [
35+
"yii\\composer\\Installer::postCreateProject"
36+
]
37+
},
38+
"extra": {
39+
"yii\\composer\\Installer::postCreateProject": {
40+
"setPermission": [
41+
{
42+
"runtime": "0777",
43+
"web/assets": "0777",
44+
"yii": "0755"
45+
}
46+
],
47+
"generateCookieValidationKey": [
48+
"config/web.php"
49+
]
50+
},
51+
"asset-installer-paths": {
52+
"npm-asset-library": "vendor/npm",
53+
"bower-asset-library": "vendor/bower"
54+
}
55+
},
56+
"repositories": {
57+
"packagist": {
58+
"type": "composer",
59+
"url": "https://packagist.phpcomposer.com"
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)