Browse Source

Merge branch 'upstream' into 364-toAscii

* upstream: (2012 commits)
  doc fix.
  Changed the signature of `urlCreator` and button creators for `yii\gridview\ActionColumn`
  parameter adjustment.
  The signature for `yii\gridview\ActionColumn::urlCreator` is changed - the `$action` parameter is moved to the first
  Fixed the signature of Schema::findUniqueIndexes().
  reverted #1598 and added a test for it
  Fix wrong array index in unique indexes for MySql
  Making accesors public
  Get DB unique indexes information
  Fixes #1610: `Html::activeCheckboxList()` and `Html::activeRadioList()` will submit an empty string if no checkbox/radio is selected
  Gii should keep horizontal layout
  Documentation at "yii\authclient" updated.
  Doc comments at "yii\authclient" updated.
  Auth clients "Choice" doc comments updated.
  Auth clients "Choice" widget javascript advanced.
  Bootstrap's dropdown encodes also trailing caret tag
  Auth clients "Choice" widget markup updated.
  Gii should keep horizontal layout
  extended from codeception testcase, added docs
  Auth clients for Facebook, GitHub, LinkedIn added.
  ...

Conflicts:
	framework/yii/helpers/BaseInflector.php
	tests/unit/framework/helpers/InflectorTest.php
tags/2.0.0-beta
Antonio Ramirez 11 years ago
parent
commit
6b3abeee1d
  1. 4
      .coveralls.yml
  2. 23
      .gitattributes
  3. 10
      .gitignore
  4. 32
      .travis.yml
  5. 4
      LICENSE.md
  6. 43
      README.md
  7. 2
      apps/advanced/.gitignore
  8. 4
      apps/advanced/LICENSE.md
  9. 69
      apps/advanced/README.md
  10. 1
      apps/advanced/backend/assets/.gitkeep
  11. 26
      apps/advanced/backend/assets/AppAsset.php
  12. 18
      apps/advanced/backend/config/assets.php
  13. 49
      apps/advanced/backend/config/main.php
  14. 5
      apps/advanced/backend/config/params.php
  15. 47
      apps/advanced/backend/controllers/SiteController.php
  16. 94
      apps/advanced/backend/views/layouts/main.php
  17. 29
      apps/advanced/backend/views/site/error.php
  18. 70
      apps/advanced/backend/views/site/index.php
  19. 26
      apps/advanced/backend/views/site/login.php
  20. 0
      apps/advanced/backend/web/.gitignore
  21. 0
      apps/advanced/backend/web/assets/.gitignore
  22. 45
      apps/advanced/backend/web/css/site.css
  23. BIN
      apps/advanced/backend/web/favicon.ico
  24. 2
      apps/advanced/backend/web/robots.txt
  25. 78
      apps/advanced/backend/www/css/site.css
  26. 24
      apps/advanced/common/config/params.php
  27. 24
      apps/advanced/common/mails/layouts/html.php
  28. 16
      apps/advanced/common/mails/passwordResetToken.php
  29. 31
      apps/advanced/common/models/LoginForm.php
  30. 100
      apps/advanced/common/models/User.php
  31. 17
      apps/advanced/composer.json
  32. 164
      apps/advanced/composer.lock
  33. 32
      apps/advanced/console/config/main.php
  34. 5
      apps/advanced/console/config/params.php
  35. 22
      apps/advanced/console/migrations/m130524_201442_init.php
  36. 11
      apps/advanced/environments/dev/backend/config/main-local.php
  37. 3
      apps/advanced/environments/dev/backend/config/params-local.php
  38. 14
      apps/advanced/environments/dev/backend/web/index.php
  39. 17
      apps/advanced/environments/dev/backstage/config/main-local.php
  40. 3
      apps/advanced/environments/dev/backstage/config/params-local.php
  41. 14
      apps/advanced/environments/dev/backstage/www/index.php
  42. 4
      apps/advanced/environments/dev/common/config/params-local.php
  43. 4
      apps/advanced/environments/dev/console/config/main-local.php
  44. 4
      apps/advanced/environments/dev/console/config/params-local.php
  45. 24
      apps/advanced/environments/dev/frontend/config/main-local.php
  46. 4
      apps/advanced/environments/dev/frontend/config/params-local.php
  47. 14
      apps/advanced/environments/dev/frontend/web/index.php
  48. 15
      apps/advanced/environments/dev/frontend/www/index.php
  49. 6
      apps/advanced/environments/dev/yii
  50. 44
      apps/advanced/environments/index.php
  51. 3
      apps/advanced/environments/prod/backend/config/main-local.php
  52. 3
      apps/advanced/environments/prod/backend/config/params-local.php
  53. 14
      apps/advanced/environments/prod/backend/web/index.php
  54. 3
      apps/advanced/environments/prod/backstage/config/main-local.php
  55. 3
      apps/advanced/environments/prod/backstage/config/params-local.php
  56. 14
      apps/advanced/environments/prod/backstage/www/index.php
  57. 4
      apps/advanced/environments/prod/common/config/params-local.php
  58. 4
      apps/advanced/environments/prod/console/config/main-local.php
  59. 4
      apps/advanced/environments/prod/console/config/params-local.php
  60. 4
      apps/advanced/environments/prod/frontend/config/main-local.php
  61. 4
      apps/advanced/environments/prod/frontend/config/params-local.php
  62. 14
      apps/advanced/environments/prod/frontend/web/index.php
  63. 15
      apps/advanced/environments/prod/frontend/www/index.php
  64. 6
      apps/advanced/environments/prod/yii
  65. 29
      apps/advanced/frontend/assets/AppAsset.php
  66. 18
      apps/advanced/frontend/config/assets.php
  67. 48
      apps/advanced/frontend/config/main.php
  68. 5
      apps/advanced/frontend/config/params.php
  69. 146
      apps/advanced/frontend/controllers/SiteController.php
  70. 28
      apps/advanced/frontend/models/ContactForm.php
  71. 101
      apps/advanced/frontend/views/layouts/main.php
  72. 14
      apps/advanced/frontend/views/site/about.php
  73. 57
      apps/advanced/frontend/views/site/contact.php
  74. 29
      apps/advanced/frontend/views/site/error.php
  75. 70
      apps/advanced/frontend/views/site/index.php
  76. 29
      apps/advanced/frontend/views/site/login.php
  77. 28
      apps/advanced/frontend/views/site/requestPasswordResetToken.php
  78. 28
      apps/advanced/frontend/views/site/resetPassword.php
  79. 30
      apps/advanced/frontend/views/site/signup.php
  80. 0
      apps/advanced/frontend/web/.gitignore
  81. 0
      apps/advanced/frontend/web/assets/.gitignore
  82. 45
      apps/advanced/frontend/web/css/site.css
  83. BIN
      apps/advanced/frontend/web/favicon.ico
  84. 2
      apps/advanced/frontend/web/robots.txt
  85. 66
      apps/advanced/frontend/widgets/Alert.php
  86. 78
      apps/advanced/frontend/www/css/site.css
  87. 74
      apps/advanced/init
  88. 53
      apps/advanced/requirements.php
  89. 4
      apps/basic/LICENSE.md
  90. 56
      apps/basic/README.md
  91. 1
      apps/basic/assets/.gitkeep
  92. 29
      apps/basic/assets/AppAsset.php
  93. 18
      apps/basic/codeception.yml
  94. 9
      apps/basic/commands/HelloController.php
  95. 18
      apps/basic/composer.json
  96. 164
      apps/basic/composer.lock
  97. 18
      apps/basic/config/assets.php
  98. 11
      apps/basic/config/codeception/acceptance.php
  99. 11
      apps/basic/config/codeception/functional.php
  100. 15
      apps/basic/config/codeception/unit.php
  101. Some files were not shown because too many files have changed in this diff Show More

4
.coveralls.yml

@ -0,0 +1,4 @@
service_name: travis-ci
src_dir: framework/yii
coverage_clover: tests/unit/runtime/coveralls/clover.xml
json_path: tests/unit/runtime/coveralls/coveralls-upload.json

23
.gitattributes vendored

@ -0,0 +1,23 @@
# Autodetect text files
* text=auto
# ...Unless the name matches the following overriding patterns
# Definitively text files
*.php text
*.css text
*.js text
*.txt text
*.md text
*.xml text
*.json text
*.bat text
*.sql text
*.xml text
*.yml text
# Ensure those won't be messed up with
*.png binary
*.jpg binary
*.gif binary
*.ttf binary

10
.gitignore vendored

@ -13,7 +13,15 @@ nbproject
Thumbs.db Thumbs.db
# composer vendor dir # composer vendor dir
/yii/vendor /vendor
# composer itself is not needed # composer itself is not needed
composer.phar composer.phar
# composer.lock should not be committed as we always want the latest versions
/composer.lock
# Mac DS_Store Files
.DS_Store
# local phpunit config
/phpunit.xml

32
.travis.yml

@ -1,15 +1,33 @@
language: php language: php
php: php:
- 5.3
- 5.4 - 5.4
- 5.5 - 5.5
# - hhvm # commented until composer or hhvm get fixed: https://github.com/facebook/hhvm/issues/1347
env: services:
- DB=mysql - redis-server
- memcached
- elasticsearch
- mongodb
install:
- composer self-update && composer --version
# - composer require satooshi/php-coveralls 0.6.* --dev --prefer-dist
- tests/unit/data/travis/mongodb-setup.sh
- tests/unit/data/travis/apc-setup.sh
- tests/unit/data/travis/memcache-setup.sh
- tests/unit/data/travis/cubrid-setup.sh
before_script: before_script:
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS yiitest;'; fi" - echo 'elasticsearch version ' && curl http://localhost:9200/
- psql -U postgres -c 'drop database if exists yiitest;'; - mysql -e 'CREATE DATABASE yiitest;';
- psql -U postgres -c 'create database yiitest;'; - psql -U postgres -c 'CREATE DATABASE yiitest;';
script: phpunit - tests/unit/data/travis/sphinx-setup.sh
- mongo yii2test --eval 'db.addUser("travis", "test");'
script:
- phpunit --coverage-text --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor
#after_script:
# - php vendor/bin/coveralls

4
LICENSE.md

@ -1,7 +1,7 @@
The Yii framework is free software. It is released under the terms of The Yii framework is free software. It is released under the terms of
the following BSD License. the following BSD License.
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -29,4 +29,4 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.

43
README.md

@ -1,42 +1,57 @@
Yii 2.0 Public Preview Yii PHP Framework Version 2
====================== ===========================
Thank you for choosing Yii - a high-performance component-based PHP framework. Thank you for choosing Yii 2 - a modern PHP framework designed for professional Web development.
If you are looking for a production-ready PHP framework, please use Yii 2 is a complete rewrite of its previous version Yii 1.1 which is one of the most popular PHP frameworks.
[Yii v1.1](https://github.com/yiisoft/yii). Yii 2 inherits the main spirit behind Yii for being simple, fast and highly extensible.
Yii 2 requires PHP 5.4 and embraces best practices and protocols found in modern Web application development.
Yii 2.0 is still under heavy development. We may make significant changes
without prior notices. **Yii 2.0 is not ready for production use yet.**
**Yii 2 is not ready for production use yet.** We may make significant changes without prior notices.
We expect to make the first stable release of Yii 2 in early 2014.
If you mainly want to learn Yii with no real project development requirement, we highly recommend
you start with Yii 2 as it will be our main focus for the next few years.
If you have a real project with tight schedule, you should stick to [Yii 1.1](https://github.com/yiisoft/yii)
which is the latest stable release of Yii.
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2/v/stable.png)](https://packagist.org/packages/yiisoft/yii2)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2/downloads.png)](https://packagist.org/packages/yiisoft/yii2)
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2) [![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
[![Dependency Status](https://www.versioneye.com/php/yiisoft:yii2/dev-master/badge.png)](https://www.versioneye.com/php/yiisoft:yii2/dev-master)
DIRECTORY STRUCTURE DIRECTORY STRUCTURE
------------------- -------------------
apps/ ready-to-use Web apps built on Yii 2 apps/ ready-to-use application templates
basic/ a simple app supporting user login and contact page advanced/ a template suitable for building sophisticated Web applications
basic/ a template suitable for building simple Web applications
benchmark/ an application demonstrating the performance of Yii
build/ internally used build tools build/ internally used build tools
docs/ documentation docs/ documentation
yii/ framework source files extensions/ extensions
framework/ core framework code
tests/ tests of the core framework code tests/ tests of the core framework code
REQUIREMENTS REQUIREMENTS
------------ ------------
The minimum requirement by Yii is that your Web server supports PHP 5.3.?. The minimum requirement by Yii is that your Web server supports PHP 5.4.
DOCUMENTATION DOCUMENTATION
------------- -------------
A draft of the [Definitive Guide](docs/guide/index.md) is available.
For 1.1 users, you may refer to [Upgrading from Yii 1.1](docs/guide/upgrade-from-v1.md) For 1.1 users, you may refer to [Upgrading from Yii 1.1](docs/guide/upgrade-from-v1.md)
to have a general idea of what has changed in 2.0. to have a general idea of what has changed in 2.0.
We are writing more documentation to get you started and learn more in depth.
HOW TO PARTICIPATE HOW TO PARTICIPATE
------------------ ------------------
@ -51,3 +66,5 @@ You may participate in the following ways:
- Before you start, please adopt an existing issue (labelled with "ready for adoption") or start a new one to avoid duplicated efforts. - Before you start, please adopt an existing issue (labelled with "ready for adoption") or start a new one to avoid duplicated efforts.
- Please submit a merge request after you finish development. - Please submit a merge request after you finish development.
In order to make it easier we've prepared [special `yii2-dev` Composer package](https://github.com/yiisoft/yii2/blob/master/docs/internals/getting-started.md).

2
apps/advanced/.gitignore vendored

@ -1 +1 @@
/yii /yii

4
apps/advanced/LICENSE.md

@ -1,7 +1,7 @@
The Yii framework is free software. It is released under the terms of The Yii framework is free software. It is released under the terms of
the following BSD License. the following BSD License.
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -29,4 +29,4 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.

69
apps/advanced/README.md

@ -1,17 +1,14 @@
Yii 2 Advanced Application Template Yii 2 Advanced Application Template
=================================== ===================================
**NOTE** Yii 2 and the relevant applications and extensions are still under heavy Yii 2 Advanced Application Template is a skeleton Yii 2 application best for
development. We may make significant changes without prior notices. Please do not developing complex Web applications with multiple tiers.
use them for production. Please consider using [Yii v1.1](https://github.com/yiisoft/yii)
if you have a project to be deployed for production soon.
The template includes three tiers: front end, back end, and console, each of which
is a separate Yii application.
Thank you for using Yii 2 Advanced Application Template - an application template The template is designed to work in a team development environment. It supports
that works out-of-box and can be easily customized to fit for your needs. deploying the application in different environments.
Yii 2 Advanced Application Template is best suitable for large projects requiring frontend and backend separation,
deployment in different environments, configuration nesting etc.
DIRECTORY STRUCTURE DIRECTORY STRUCTURE
@ -34,7 +31,7 @@ backend
models/ contains backend-specific model classes models/ contains backend-specific model classes
runtime/ contains files generated during runtime runtime/ contains files generated during runtime
views/ contains view files for the Web application views/ contains view files for the Web application
www/ contains the entry script and Web resources web/ contains the entry script and Web resources
frontend frontend
assets/ contains application assets such as JavaScript and CSS assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations config/ contains frontend configurations
@ -42,57 +39,40 @@ frontend
models/ contains frontend-specific model classes models/ contains frontend-specific model classes
runtime/ contains files generated during runtime runtime/ contains files generated during runtime
views/ contains view files for the Web application views/ contains view files for the Web application
www/ contains the entry script and Web resources web/ contains the entry script and Web resources
vendor/ contains dependent 3rd-party packages vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides environments/ contains environment-based overrides
``` ```
REQUIREMENTS REQUIREMENTS
------------ ------------
The minimum requirement by Yii is that your Web server supports PHP 5.3.?. The minimum requirement by this application template that your Web server supports PHP 5.4.0.
INSTALLATION INSTALLATION
------------ ------------
### Install via Composer ### Install from an Archive File
If you do not have [Composer](http://getcomposer.org/), you may download it from
[http://getcomposer.org/](http://getcomposer.org/) or run the following command on Linux/Unix/MacOS:
~~~
curl -s http://getcomposer.org/installer | php
~~~
You can then install the application using the following command:
~~~
php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced yii-advanced
~~~
Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
a directory named `advanced` that is directly under the Web root.
### Install from an Archive File Then follow the instructions given in "GETTING STARTED".
This is not currently available. We will provide it when Yii 2 is formally released.
### Install via Composer
### Install from development repository If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
If you've cloned the [Yii 2 framework main development repository](https://github.com/yiisoft/yii2) you You can then install the application using the following command:
can bootstrap your application with:
~~~ ~~~
cd yii2/apps/advanced php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced advanced
php composer.phar create-project
~~~ ~~~
*Note: If the above command fails with `[RuntimeException] Not enough arguments.` run
`php composer.phar self-update` to obtain an updated version of composer which supports creating projects
from local packages.*
GETTING STARTED GETTING STARTED
--------------- ---------------
@ -100,14 +80,11 @@ GETTING STARTED
After you install the application, you have to conduct the following steps to initialize 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. the installed application. You only need to do these once for all.
1. Execute the `init` command and select `dev` as environment. 1. Run command `init` to initialize the application with a specific environment.
2. Create a new database. It is assumed that MySQL InnoDB is used. If not, adjust `console/migrations/m130524_201442_init.php`. 2. Create a new database and adjust the `components.db` configuration in `common/config/params.php` accordingly.
3. In `common/config/params.php` set your database details in `components.db` values. 3. Run command `yii migrate` to apply DB migrations.
Now you should be able to access: Now you should be able to access:
- the frontend using the URL `http://localhost/yii-advanced/frontend/www/` - the frontend using the URL `http://localhost/advanced/frontend/web/`
- the backend using the URL `http://localhost/yii-advanced/backend/www/` - the backend using the URL `http://localhost/advanced/backend/web/`
assuming `yii-advanced` is directly under the document root of your Web server.

1
apps/advanced/backend/assets/.gitkeep

@ -1 +0,0 @@
*

26
apps/advanced/backend/assets/AppAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace backend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = ['css/site.css'];
public $js = [];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

18
apps/advanced/backend/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

49
apps/advanced/backend/config/main.php

@ -1,5 +1,5 @@
<?php <?php
$rootDir = __DIR__ . '/../..'; $rootDir = dirname(dirname(__DIR__));
$params = array_merge( $params = array_merge(
require($rootDir . '/common/config/params.php'), require($rootDir . '/common/config/params.php'),
@ -8,33 +8,34 @@ $params = array_merge(
require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );
return array( return [
'id' => 'app-backend', 'id' => 'app-backend',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'vendorPath' => $rootDir . '/vendor',
'preload' => array('log'), 'preload' => ['log'],
'controllerNamespace' => 'backend\controllers', 'controllerNamespace' => 'backend\controllers',
'modules' => array( 'modules' => [],
), 'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'),
'components' => array( 'components' => [
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'user' => array( 'mail' => $params['components.mail'],
'class' => 'yii\web\User', 'user' => [
'identityClass' => 'common\models\User', 'identityClass' => 'common\models\User',
), 'enableAutoLogin' => true,
'assetManager' => array( ],
'bundles' => require(__DIR__ . '/assets.php'), 'log' => [
), 'traceLevel' => YII_DEBUG ? 3 : 0,
'log' => array( 'targets' => [
'class' => 'yii\logging\Router', [
'targets' => array( 'class' => 'yii\log\FileTarget',
array( 'levels' => ['error', 'warning'],
'class' => 'yii\logging\FileTarget', ],
'levels' => array('error', 'warning'), ],
), ],
), 'errorHandler' => [
), 'errorAction' => 'site/error',
), ],
],
'params' => $params, 'params' => $params,
); ];

5
apps/advanced/backend/config/params.php

@ -1,5 +1,4 @@
<?php <?php
return [
return array(
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
); ];

47
apps/advanced/backend/controllers/SiteController.php

@ -8,26 +8,59 @@ use common\models\LoginForm;
class SiteController extends Controller class SiteController extends Controller
{ {
public function behaviors()
{
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionIndex() public function actionIndex()
{ {
echo $this->render('index'); return $this->render('index');
} }
public function actionLogin() public function actionLogin()
{ {
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm(); $model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) { if ($model->load($_POST) && $model->login()) {
Yii::$app->response->redirect(array('site/index')); return $this->goBack();
} else { } else {
echo $this->render('login', array( return $this->render('login', [
'model' => $model, 'model' => $model,
)); ]);
} }
} }
public function actionLogout() public function actionLogout()
{ {
Yii::$app->getUser()->logout(); Yii::$app->user->logout();
Yii::$app->getResponse()->redirect(array('site/index')); return $this->goHome();
} }
} }

94
apps/advanced/backend/views/layouts/main.php

@ -1,64 +1,64 @@
<?php <?php
use backend\assets\AppAsset;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\Menu; use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use yii\debug\Toolbar;
/** /**
* @var $this \yii\base\View * @var \yii\web\View $this
* @var $content string * @var string $content
*/ */
$this->registerAssetBundle('app'); AppAsset::register($this);
?> ?>
<?php $this->beginPage(); ?> <?php $this->beginPage() ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="<?= Yii::$app->language ?>">
<head> <head>
<meta charset="utf-8"/> <meta charset="<?= Yii::$app->charset ?>"/>
<title><?php echo Html::encode($this->title); ?></title> <title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?> <?php $this->head() ?>
</head> </head>
<body> <body>
<div class="container"> <?php $this->beginBody() ?>
<?php $this->beginBody(); ?> <?php
<div class="masthead"> NavBar::begin([
<h3 class="muted">My Company</h3> 'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="navbar"> <div class="container">
<div class="navbar-inner"> <?= Breadcrumbs::widget([
<div class="container"> 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
<?php echo Menu::widget(array( ]) ?>
'options' => array('class' => 'nav'), <?= $content ?>
'items' => array(
array('label' => 'Home', 'url' => array('/site/index')),
Yii::$app->user->isGuest ?
array('label' => 'Login', 'url' => array('/site/login')) :
array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')),
),
)); ?>
</div>
</div>
</div>
<!-- /.navbar -->
</div> </div>
<?php echo Breadcrumbs::widget(array( <footer class="footer">
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), <div class="container">
)); ?> <p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<?php echo $content; ?> <p class="pull-right"><?= Yii::powered() ?></p>
</div>
<hr> </footer>
<div class="footer"> <?php $this->endBody() ?>
<p>&copy; My Company <?php echo date('Y'); ?></p>
<p>
<?php echo Yii::powered(); ?>
Template by <a href="http://twitter.github.io/bootstrap/">Twitter Bootstrap</a>
</p>
</div>
<?php $this->endBody(); ?>
</div>
<?php echo Toolbar::widget(); ?>
</body> </body>
</html> </html>
<?php $this->endPage(); ?> <?php $this->endPage() ?>

29
apps/advanced/backend/views/site/error.php

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
/**
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception
*/
$this->title = $name;
?>
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>

70
apps/advanced/backend/views/site/index.php

@ -1,47 +1,53 @@
<?php <?php
/** /**
* @var yii\base\View $this * @var yii\web\View $this
*/ */
$this->title = 'Welcome'; $this->title = 'My Yii Application';
?> ?>
<div class="jumbotron"> <div class="site-index">
<h1>Welcome!</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus <div class="jumbotron">
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> <h1>Congratulations!</h1>
<a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a>
</div>
<hr> <p class="lead">You have successfully created your Yii-powered application.</p>
<!-- Example row of columns --> <p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
<div class="row-fluid"> </div>
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris <div class="body-content">
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p> <div class="row">
</div> <div class="col-lg-4">
<div class="span4"> <h2>Heading</h2>
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
Donec sed odio dui. </p> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn" href="#">View details &raquo;</a></p> <p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation &raquo;</a></p>
</div> </div>
<div class="span4"> <div class="col-lg-4">
<h2>Heading</h2> <h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
massa.</p> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/forum/">Yii Forum &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/extensions/">Yii Extensions &raquo;</a></p>
</div>
</div>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div> </div>
</div> </div>

26
apps/advanced/backend/views/site/login.php

@ -3,22 +3,28 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/** /**
* @var yii\base\View $this * @var yii\web\View $this
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model * @var app\models\LoginForm $model
*/ */
$this->title = 'Login'; $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p> <p>Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin(array('options' => array('class' => 'form-horizontal'))); ?> <div class="row">
<?php echo $form->field($model, 'username')->textInput(); ?> <div class="col-lg-5">
<?php echo $form->field($model, 'password')->passwordInput(); ?> <?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?> <?= $form->field($model, 'username') ?>
<div class="form-actions"> <?= $form->field($model, 'password')->passwordInput() ?>
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?> <?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div> </div>
<?php ActiveForm::end(); ?> </div>

0
apps/advanced/backend/www/.gitignore → apps/advanced/backend/web/.gitignore vendored

0
apps/advanced/backend/www/assets/.gitignore → apps/advanced/backend/web/assets/.gitignore vendored

45
apps/advanced/backend/web/css/site.css

@ -0,0 +1,45 @@
body {
padding-top: 70px;
}
.footer {
border-top: 1px solid #ddd;
margin-top: 30px;
padding-top: 15px;
padding-bottom: 30px;
}
.jumbotron {
text-align: center;
background-color: transparent;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.not-set {
color: #c55;
font-style: italic;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after { content: /*"\e113"*/"\e151"; }
a.desc:after { content: /*"\e114"*/"\e152"; }
.sort-numerical a.asc:after { content: "\e153"; }
.sort-numerical a.desc:after { content: "\e154"; }
.sort-ordinal a.asc:after { content: "\e155"; }
.sort-ordinal a.desc:after { content: "\e156"; }

BIN
apps/advanced/backend/web/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

2
apps/advanced/backend/web/robots.txt

@ -0,0 +1,2 @@
User-Agent: *
Disallow: /

78
apps/advanced/backend/www/css/site.css

@ -1,78 +0,0 @@
body {
padding-top: 20px;
padding-bottom: 60px;
}
/* Custom container */
.container {
margin: 0 auto;
max-width: 1000px;
}
.container > hr {
margin: 60px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 80px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 100px;
line-height: 1;
}
.jumbotron .lead {
font-size: 24px;
line-height: 1.25;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
/* Supporting marketing content */
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar .navbar-inner {
padding: 0;
}
.navbar .nav {
margin: 0;
display: table;
width: 100%;
}
.navbar .nav li {
display: table-cell;
width: 1%;
float: none;
}
.navbar .nav li a {
font-weight: bold;
text-align: center;
border-left: 1px solid rgba(255, 255, 255, .75);
border-right: 1px solid rgba(0, 0, 0, .1);
}
.navbar .nav li:first-child a {
border-left: 0;
border-radius: 3px 0 0 3px;
}
.navbar .nav li:last-child a {
border-right: 0;
border-radius: 0 3px 3px 0;
}

24
apps/advanced/common/config/params.php

@ -1,16 +1,28 @@
<?php <?php
return array( Yii::setAlias('common', realpath(__DIR__ . '/../'));
Yii::setAlias('frontend', realpath(__DIR__ . '/../../frontend'));
Yii::setAlias('backend', realpath(__DIR__ . '/../../backend'));
Yii::setAlias('console', realpath(__DIR__ . '/../../console'));
return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
'supportEmail' => 'support@example.com',
'components.cache' => array( 'components.cache' => [
'class' => 'yii\caching\FileCache', 'class' => 'yii\caching\FileCache',
), ],
'components.mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mails',
],
'components.db' => array( 'components.db' => [
'class' => 'yii\db\Connection', 'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced', 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root', 'username' => 'root',
'password' => '', 'password' => '',
), 'charset' => 'utf8',
); ],
];

24
apps/advanced/common/mails/layouts/html.php

@ -0,0 +1,24 @@
<?php
use yii\helpers\Html;
use yii\mail\BaseMessage;
/**
* @var \yii\web\View $this
* @var BaseMessage $content
*/
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

16
apps/advanced/common/mails/passwordResetToken.php

@ -0,0 +1,16 @@
<?php
use yii\helpers\Html;
/**
* @var yii\web\View $this
* @var common\models\User $user;
*/
$resetLink = Yii::$app->urlManager->createAbsoluteUrl('site/reset-password', ['token' => $user->password_reset_token]);
?>
Hello <?= Html::encode($user->username) ?>,
Follow the link below to reset your password:
<?= Html::a(Html::encode($resetLink), $resetLink) ?>

31
apps/advanced/common/models/LoginForm.php

@ -14,19 +14,21 @@ class LoginForm extends Model
public $password; public $password;
public $rememberMe = true; public $rememberMe = true;
private $_user = false;
/** /**
* @return array the validation rules. * @return array the validation rules.
*/ */
public function rules() public function rules()
{ {
return array( return [
// username and password are both required // username and password are both required
array('username, password', 'required'), [['username', 'password'], 'required'],
// password is validated by validatePassword() // password is validated by validatePassword()
array('password', 'validatePassword'), ['password', 'validatePassword'],
// rememberMe must be a boolean value // rememberMe must be a boolean value
array('rememberMe', 'boolean'), ['rememberMe', 'boolean'],
); ];
} }
/** /**
@ -35,7 +37,7 @@ class LoginForm extends Model
*/ */
public function validatePassword() public function validatePassword()
{ {
$user = User::findByUsername($this->username); $user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) { if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.'); $this->addError('password', 'Incorrect username or password.');
} }
@ -48,11 +50,22 @@ class LoginForm extends Model
public function login() public function login()
{ {
if ($this->validate()) { if ($this->validate()) {
$user = User::findByUsername($this->username); return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
return true;
} else { } else {
return false; return false;
} }
} }
/**
* Finds user by [[username]]
*
* @return User|null
*/
private function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
} }

100
apps/advanced/common/models/User.php

@ -2,8 +2,8 @@
namespace common\models; namespace common\models;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\helpers\SecurityHelper; use yii\helpers\Security;
use yii\web\Identity; use yii\web\IdentityInterface;
/** /**
* Class User * Class User
@ -12,6 +12,7 @@ use yii\web\Identity;
* @property integer $id * @property integer $id
* @property string $username * @property string $username
* @property string $password_hash * @property string $password_hash
* @property string $password_reset_token
* @property string $email * @property string $email
* @property string $auth_key * @property string $auth_key
* @property integer $role * @property integer $role
@ -19,7 +20,7 @@ use yii\web\Identity;
* @property integer $create_time * @property integer $create_time
* @property integer $update_time * @property integer $update_time
*/ */
class User extends ActiveRecord implements Identity class User extends ActiveRecord implements IdentityInterface
{ {
/** /**
* @var string the raw password. Used to collect password input and isn't saved in database * @var string the raw password. Used to collect password input and isn't saved in database
@ -33,79 +34,108 @@ class User extends ActiveRecord implements Identity
public function behaviors() public function behaviors()
{ {
return array( return [
'timestamp' => array( 'timestamp' => [
'class' => 'yii\behaviors\AutoTimestamp', 'class' => 'yii\behaviors\AutoTimestamp',
'attributes' => array( 'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => array('create_time', 'update_time'), ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time', ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time',
), ],
), ],
); ];
} }
/**
* Finds an identity by the given ID.
*
* @param string|integer $id the ID to be looked for
* @return IdentityInterface|null the identity object that matches the given ID.
*/
public static function findIdentity($id) public static function findIdentity($id)
{ {
return static::find($id); return static::find($id);
} }
/**
* Finds user by username
*
* @param string $username
* @return null|User
*/
public static function findByUsername($username) public static function findByUsername($username)
{ {
return static::find(array('username' => $username, 'status' => static::STATUS_ACTIVE)); return static::find(['username' => $username, 'status' => static::STATUS_ACTIVE]);
} }
/**
* @return int|string current user ID
*/
public function getId() public function getId()
{ {
return $this->id; return $this->id;
} }
/**
* @return string current user auth key
*/
public function getAuthKey() public function getAuthKey()
{ {
return $this->auth_key; return $this->auth_key;
} }
/**
* @param string $authKey
* @return boolean if auth key is valid for current user
*/
public function validateAuthKey($authKey) public function validateAuthKey($authKey)
{ {
return $this->auth_key === $authKey; return $this->getAuthKey() === $authKey;
} }
/**
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password) public function validatePassword($password)
{ {
return SecurityHelper::validatePassword($password, $this->password_hash); return Security::validatePassword($password, $this->password_hash);
} }
public function rules() public function rules()
{ {
return array( return [
array('username', 'filter', 'filter' => 'trim'), ['username', 'filter', 'filter' => 'trim'],
array('username', 'required'), ['username', 'required'],
array('username', 'length', 'min' => 2, 'max' => 255), ['username', 'string', 'min' => 2, 'max' => 255],
array('email', 'filter', 'filter' => 'trim'), ['email', 'filter', 'filter' => 'trim'],
array('email', 'required'), ['email', 'required'],
array('email', 'email'), ['email', 'email'],
array('email', 'unique', 'message' => 'This email address has already been taken.'), ['email', 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'],
['email', 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'],
array('password', 'required'),
array('password', 'length', 'min' => 6), ['password', 'required'],
); ['password', 'string', 'min' => 6],
];
} }
public function scenarios() public function scenarios()
{ {
return array( return [
'signup' => array('username', 'email', 'password'), 'signup' => ['username', 'email', 'password'],
'login' => array('username', 'password'), 'resetPassword' => ['password'],
); 'requestPasswordResetToken' => ['email'],
];
} }
public function beforeSave($insert) public function beforeSave($insert)
{ {
if(parent::beforeSave($insert)) { if (parent::beforeSave($insert)) {
if($this->isNewRecord) { if (($this->isNewRecord || $this->getScenario() === 'resetPassword') && !empty($this->password)) {
if(!empty($this->password)) { $this->password_hash = Security::generatePasswordHash($this->password);
$this->password_hash = SecurityHelper::generatePasswordHash($this->password); }
} if ($this->isNewRecord) {
$this->auth_key = Security::generateRandomKey();
} }
return true; return true;
} }

17
apps/advanced/composer.json

@ -14,25 +14,28 @@
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.4.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "*",
"yiisoft/yii2-composer": "dev-master" "yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*"
}, },
"scripts": { "scripts": {
"post-create-project-cmd": [ "post-create-project-cmd": [
"yii\\composer\\InstallHandler::setPermissions" "yii\\composer\\Installer::setPermission"
] ]
}, },
"extra": { "extra": {
"yii-install-writable": [ "writable": [
"backend/runtime", "backend/runtime",
"backend/www/assets", "backend/web/assets",
"console/runtime", "console/runtime",
"console/migrations", "console/migrations",
"frontend/runtime", "frontend/runtime",
"frontend/www/assets" "frontend/web/assets"
] ]
} }
} }

164
apps/advanced/composer.lock generated

@ -1,164 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "2d1053fbaaf2044054f273a71d0ccde0",
"packages": [
{
"name": "yiisoft/yii2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-framework.git",
"reference": "3ad6334be076a80df3b2ea0b57f38bd0c6901989"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/3ad6334be076a80df3b2ea0b57f38bd0c6901989",
"reference": "3ad6334be076a80df3b2ea0b57f38bd0c6901989",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"lib-pcre": "*",
"php": ">=5.3.7"
},
"suggest": {
"ezyang/htmlpurifier": "Required by HtmlPurifier.",
"michelf/php-markdown": "Required by Markdown.",
"smarty/smarty": "Required by SmartyViewRenderer.",
"twig/twig": "Required by TwigViewRenderer."
},
"type": "library",
"autoload": {
"psr-0": {
"yii\\": "/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Qiang Xue",
"email": "qiang.xue@gmail.com",
"homepage": "http://www.yiiframework.com/",
"role": "Founder and project lead"
},
{
"name": "Alexander Makarov",
"email": "sam@rmcreative.ru",
"homepage": "http://rmcreative.ru/",
"role": "Core framework development"
},
{
"name": "Maurizio Domba",
"homepage": "http://mdomba.info/",
"role": "Core framework development"
},
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc",
"homepage": "http://cebe.cc/",
"role": "Core framework development"
},
{
"name": "Wei Zhuo",
"email": "weizhuo@gmail.com",
"role": "Project site maintenance and development"
},
{
"name": "Sebastián Thierer",
"email": "sebas@artfos.com",
"role": "Component development"
},
{
"name": "Jeffrey Winesett",
"email": "jefftulsa@gmail.com",
"role": "Documentation and marketing"
},
{
"name": "Timur Ruziev",
"email": "resurtm@gmail.com",
"homepage": "http://resurtm.com/",
"role": "Core framework development"
},
{
"name": "Paul Klimov",
"email": "klimov.paul@gmail.com",
"role": "Core framework development"
}
],
"description": "Yii2 Web Programming Framework",
"homepage": "http://www.yiiframework.com/",
"keywords": [
"framework",
"yii"
],
"time": "2013-06-02 19:19:29"
},
{
"name": "yiisoft/yii2-composer",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-composer.git",
"reference": "7ce4060faca940b836ab88de207638940a0a0568"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7ce4060faca940b836ab88de207638940a0a0568",
"reference": "7ce4060faca940b836ab88de207638940a0a0568",
"shasum": ""
},
"require": {
"yiisoft/yii2": "*"
},
"type": "library",
"autoload": {
"psr-0": {
"yii\\composer": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Qiang Xue",
"email": "qiang.xue@gmail.com",
"homepage": "http://www.yiiframework.com/",
"role": "Founder and project lead"
}
],
"description": "The composer integration for the Yii framework",
"keywords": [
"composer",
"install",
"update",
"yii"
],
"time": "2013-05-23 19:12:45"
}
],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "dev",
"stability-flags": {
"yiisoft/yii2": 20,
"yiisoft/yii2-composer": 20
},
"platform": {
"php": ">=5.3.0"
},
"platform-dev": [
]
}

32
apps/advanced/console/config/main.php

@ -8,26 +8,26 @@ $params = array_merge(
require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );
return array( return [
'id' => 'app-console', 'id' => 'app-console',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'preload' => array('log'),
'controllerNamespace' => 'console\controllers', 'controllerNamespace' => 'console\controllers',
'modules' => array( 'modules' => [
), ],
'components' => array( 'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'log' => array( 'mail' => $params['components.mail'],
'class' => 'yii\logging\Router', 'log' => [
'targets' => array( 'targets' => [
array( [
'class' => 'yii\logging\FileTarget', 'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'), 'levels' => ['error', 'warning'],
), ],
), ],
), ],
), ],
'params' => $params, 'params' => $params,
); ];

5
apps/advanced/console/config/params.php

@ -1,5 +1,4 @@
<?php <?php
return [
return array(
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
); ];

22
apps/advanced/console/migrations/m130524_201442_init.php

@ -6,20 +6,24 @@ class m130524_201442_init extends \yii\db\Migration
{ {
public function up() public function up()
{ {
// MySQL-specific table options. Adjust if you plan working with another DBMS $tableOptions = null;
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable('tbl_user', array( $this->createTable('tbl_user', [
'id' => Schema::TYPE_PK, 'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING.' NOT NULL', 'username' => Schema::TYPE_STRING . ' NOT NULL',
'password_hash' => Schema::TYPE_STRING.' NOT NULL', 'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
'email' => Schema::TYPE_STRING.' NOT NULL', 'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
'role' => 'tinyint NOT NULL DEFAULT 10', 'password_reset_token' => Schema::TYPE_STRING . '(32)',
'email' => Schema::TYPE_STRING . ' NOT NULL',
'role' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
'status' => 'tinyint NOT NULL DEFAULT 10', 'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
'create_time' => Schema::TYPE_INTEGER.' NOT NULL', 'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
'update_time' => Schema::TYPE_INTEGER.' NOT NULL', 'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
), $tableOptions); ], $tableOptions);
} }
public function down() public function down()

11
apps/advanced/environments/dev/backend/config/main-local.php

@ -0,0 +1,11 @@
<?php
return [
'preload' => [
//'debug',
],
'modules' => [
// 'debug' => [
// 'class' => 'yii\debug\Module',
// ],
],
];

3
apps/advanced/environments/dev/backend/config/params-local.php

@ -0,0 +1,3 @@
<?php
return [
];

14
apps/advanced/environments/dev/backend/web/index.php

@ -0,0 +1,14 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

17
apps/advanced/environments/dev/backstage/config/main-local.php

@ -1,17 +0,0 @@
<?php
return array(
'modules' => array(
// 'debug' => array(
// 'class' => 'yii\debug\Module',
// ),
),
'components' => array(
'log' => array(
'targets' => array(
// array(
// 'class' => 'yii\logging\DebugTarget',
// )
),
),
),
);

3
apps/advanced/environments/dev/backstage/config/params-local.php

@ -1,3 +0,0 @@
<?php
return array(
);

14
apps/advanced/environments/dev/backstage/www/index.php

@ -1,14 +0,0 @@
<?php
// comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

4
apps/advanced/environments/dev/common/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/dev/console/config/main-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/dev/console/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

24
apps/advanced/environments/dev/frontend/config/main-local.php

@ -1,17 +1,11 @@
<?php <?php
return array( return [
'modules' => array( 'preload' => [
// 'debug' => array( //'debug',
],
'modules' => [
// 'debug' => [
// 'class' => 'yii\debug\Module', // 'class' => 'yii\debug\Module',
// ), // ],
), ],
'components' => array( ];
'log' => array(
'targets' => array(
// array(
// 'class' => 'yii\logging\DebugTarget',
// )
),
),
),
);

4
apps/advanced/environments/dev/frontend/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

14
apps/advanced/environments/dev/frontend/web/index.php

@ -0,0 +1,14 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

15
apps/advanced/environments/dev/frontend/www/index.php

@ -1,15 +0,0 @@
<?php
// comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

6
apps/advanced/environments/dev/yii

@ -9,12 +9,13 @@
*/ */
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
// fcgi doesn't have STDIN defined by default // fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main.php'),
@ -22,4 +23,5 @@ $config = yii\helpers\ArrayHelper::merge(
); );
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$application->run(); $exitCode = $application->run();
exit($exitCode);

44
apps/advanced/environments/index.php

@ -6,33 +6,33 @@
* format: * format:
* *
* ```php * ```php
* return array( * return [
* 'environment name' => array( * 'environment name' => [
* 'path' => 'directory storing the local files', * 'path' => 'directory storing the local files',
* 'writable' => array( * 'writable' => [
* // list of directories that should be set writable * // list of directories that should be set writable
* ), * ],
* ), * ],
* ); * ];
* ``` * ```
*/ */
return array( return [
'Development' => array( 'Development' => [
'path' => 'dev', 'path' => 'dev',
'writable' => array( 'writable' => [
// handled by composer.json already // handled by composer.json already
), ],
'executable' => array( 'executable' => [
'yiic', 'yii',
), ],
), ],
'Production' => array( 'Production' => [
'path' => 'prod', 'path' => 'prod',
'writable' => array( 'writable' => [
// handled by composer.json already // handled by composer.json already
), ],
'executable' => array( 'executable' => [
'yiic', 'yii',
), ],
), ],
); ];

3
apps/advanced/environments/prod/backend/config/main-local.php

@ -0,0 +1,3 @@
<?php
return [
];

3
apps/advanced/environments/prod/backend/config/params-local.php

@ -0,0 +1,3 @@
<?php
return [
];

14
apps/advanced/environments/prod/backend/web/index.php

@ -0,0 +1,14 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

3
apps/advanced/environments/prod/backstage/config/main-local.php

@ -1,3 +0,0 @@
<?php
return array(
);

3
apps/advanced/environments/prod/backstage/config/params-local.php

@ -1,3 +0,0 @@
<?php
return array(
);

14
apps/advanced/environments/prod/backstage/www/index.php

@ -1,14 +0,0 @@
<?php
// comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', false);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

4
apps/advanced/environments/prod/common/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/prod/console/config/main-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/prod/console/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/prod/frontend/config/main-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

4
apps/advanced/environments/prod/frontend/config/params-local.php

@ -1,3 +1,3 @@
<?php <?php
return array( return [
); ];

14
apps/advanced/environments/prod/frontend/web/index.php

@ -0,0 +1,14 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

15
apps/advanced/environments/prod/frontend/www/index.php

@ -1,15 +0,0 @@
<?php
// comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', false);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();

6
apps/advanced/environments/prod/yii

@ -9,12 +9,13 @@
*/ */
defined('YII_DEBUG') or define('YII_DEBUG', false); defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
// fcgi doesn't have STDIN defined by default // fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main.php'),
@ -22,4 +23,5 @@ $config = yii\helpers\ArrayHelper::merge(
); );
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$application->run(); $exitCode = $application->run();
exit($exitCode);

29
apps/advanced/frontend/assets/AppAsset.php

@ -0,0 +1,29 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

18
apps/advanced/frontend/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

48
apps/advanced/frontend/config/main.php

@ -8,33 +8,35 @@ $params = array_merge(
require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );
return array( return [
'id' => 'app-frontend', 'id' => 'app-frontend',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'vendorPath' => $rootDir . '/vendor',
'preload' => array('log'),
'controllerNamespace' => 'frontend\controllers', 'controllerNamespace' => 'frontend\controllers',
'modules' => array( 'modules' => [
), 'gii' => 'yii\gii\Module'
'components' => array( ],
'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'], 'db' => $params['components.db'],
'cache' => $params['components.cache'], 'cache' => $params['components.cache'],
'user' => array( 'mail' => $params['components.mail'],
'class' => 'yii\web\User', 'user' => [
'identityClass' => 'common\models\User', 'identityClass' => 'common\models\User',
), 'enableAutoLogin' => true,
'assetManager' => array( ],
'bundles' => require(__DIR__ . '/assets.php'), 'log' => [
), 'traceLevel' => YII_DEBUG ? 3 : 0,
'log' => array( 'targets' => [
'class' => 'yii\logging\Router', [
'targets' => array( 'class' => 'yii\log\FileTarget',
array( 'levels' => ['error', 'warning'],
'class' => 'yii\logging\FileTarget', ],
'levels' => array('error', 'warning'), ],
), ],
), 'errorHandler' => [
), 'errorAction' => 'site/error',
), ],
],
'params' => $params, 'params' => $params,
); ];

5
apps/advanced/frontend/config/params.php

@ -1,5 +1,4 @@
<?php <?php
return [
return array(
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
); ];

146
apps/advanced/frontend/controllers/SiteController.php

@ -6,56 +6,166 @@ use Yii;
use yii\web\Controller; use yii\web\Controller;
use common\models\LoginForm; use common\models\LoginForm;
use frontend\models\ContactForm; use frontend\models\ContactForm;
use common\models\User;
use yii\web\BadRequestHttpException;
use yii\helpers\Security;
class SiteController extends Controller class SiteController extends Controller
{ {
public function behaviors()
{
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
public function actions() public function actions()
{ {
return array( return [
'captcha' => array( 'error' => [
'class' => 'yii\web\CaptchaAction', 'class' => 'yii\web\ErrorAction',
), ],
); 'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
} }
public function actionIndex() public function actionIndex()
{ {
echo $this->render('index'); return $this->render('index');
} }
public function actionLogin() public function actionLogin()
{ {
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm(); $model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) { if ($model->load($_POST) && $model->login()) {
Yii::$app->response->redirect(array('site/index')); return $this->goBack();
} else { } else {
echo $this->render('login', array( return $this->render('login', [
'model' => $model, 'model' => $model,
)); ]);
} }
} }
public function actionLogout() public function actionLogout()
{ {
Yii::$app->getUser()->logout(); Yii::$app->user->logout();
Yii::$app->getResponse()->redirect(array('site/index')); return $this->goHome();
} }
public function actionContact() public function actionContact()
{ {
$model = new ContactForm; $model = new ContactForm;
if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) { if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted'); Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
Yii::$app->response->refresh(); return $this->refresh();
} else { } else {
echo $this->render('contact', array( return $this->render('contact', [
'model' => $model, 'model' => $model,
)); ]);
} }
} }
public function actionAbout() public function actionAbout()
{ {
echo $this->render('about'); return $this->render('about');
}
public function actionSignup()
{
$model = new User();
$model->setScenario('signup');
if ($model->load($_POST) && $model->save()) {
if (Yii::$app->getUser()->login($model)) {
return $this->goHome();
}
}
return $this->render('signup', [
'model' => $model,
]);
}
public function actionRequestPasswordReset()
{
$model = new User();
$model->scenario = 'requestPasswordResetToken';
if ($model->load($_POST) && $model->validate()) {
if ($this->sendPasswordResetEmail($model->email)) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
} else {
Yii::$app->getSession()->setFlash('error', 'There was an error sending email.');
}
}
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
}
public function actionResetPassword($token)
{
$model = User::find([
'password_reset_token' => $token,
'status' => User::STATUS_ACTIVE,
]);
if (!$model) {
throw new BadRequestHttpException('Wrong password reset token.');
}
$model->scenario = 'resetPassword';
if ($model->load($_POST) && $model->save()) {
Yii::$app->getSession()->setFlash('success', 'New password was saved.');
return $this->goHome();
}
return $this->render('resetPassword', [
'model' => $model,
]);
}
private function sendPasswordResetEmail($email)
{
$user = User::find([
'status' => User::STATUS_ACTIVE,
'email' => $email,
]);
if (!$user) {
return false;
}
$user->password_reset_token = Security::generateRandomKey();
if ($user->save(false)) {
return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user])
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
->setTo($email)
->setSubject('Password reset for ' . \Yii::$app->name)
->send();
}
return false;
} }
} }

28
apps/advanced/frontend/models/ContactForm.php

@ -2,6 +2,7 @@
namespace frontend\models; namespace frontend\models;
use Yii;
use yii\base\Model; use yii\base\Model;
/** /**
@ -20,14 +21,14 @@ class ContactForm extends Model
*/ */
public function rules() public function rules()
{ {
return array( return [
// name, email, subject and body are required // name, email, subject and body are required
array('name, email, subject, body', 'required'), [['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address // email has to be a valid email address
array('email', 'email'), ['email', 'email'],
// verifyCode needs to be entered correctly // verifyCode needs to be entered correctly
array('verifyCode', 'captcha'), ['verifyCode', 'captcha'],
); ];
} }
/** /**
@ -35,9 +36,9 @@ class ContactForm extends Model
*/ */
public function attributeLabels() public function attributeLabels()
{ {
return array( return [
'verifyCode' => 'Verification Code', 'verifyCode' => 'Verification Code',
); ];
} }
/** /**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email) public function contact($email)
{ {
if ($this->validate()) { if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; Yii::$app->mail->compose()
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; ->setTo($email)
$headers = "From: $name <{$this->email}>\r\n" . ->setFrom([$this->email => $this->name])
"Reply-To: {$this->email}\r\n" . ->setSubject($this->subject)
"MIME-Version: 1.0\r\n" . ->setTextBody($this->body)
"Content-type: text/plain; charset=UTF-8"; ->send();
mail($email, $subject, $this->body, $headers);
return true; return true;
} else { } else {
return false; return false;

101
apps/advanced/frontend/views/layouts/main.php

@ -1,66 +1,69 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\Menu; use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use yii\debug\Toolbar; use frontend\assets\AppAsset;
use frontend\widgets\Alert;
/** /**
* @var $this \yii\base\View * @var \yii\web\View $this
* @var $content string * @var string $content
*/ */
$this->registerAssetBundle('app'); AppAsset::register($this);
?> ?>
<?php $this->beginPage(); ?> <?php $this->beginPage() ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="<?= Yii::$app->language ?>">
<head> <head>
<meta charset="utf-8"/> <meta charset="<?= Yii::$app->charset ?>"/>
<title><?php echo Html::encode($this->title); ?></title> <title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?> <?php $this->head() ?>
</head> </head>
<body> <body>
<div class="container"> <?php $this->beginBody() ?>
<?php $this->beginBody(); ?> <?php
<div class="masthead"> NavBar::begin([
<h3 class="muted">My Company</h3> 'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="navbar"> <div class="container">
<div class="navbar-inner"> <?= Breadcrumbs::widget([
<div class="container"> 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
<?php echo Menu::widget(array( ]) ?>
'options' => array('class' => 'nav'), <?= Alert::widget() ?>
'items' => array( <?= $content ?>
array('label' => 'Home', 'url' => array('/site/index')),
array('label' => 'About', 'url' => array('/site/about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
Yii::$app->user->isGuest ?
array('label' => 'Login', 'url' => array('/site/login')) :
array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')),
),
)); ?>
</div>
</div>
</div>
<!-- /.navbar -->
</div> </div>
<?php echo Breadcrumbs::widget(array( <footer class="footer">
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), <div class="container">
)); ?> <p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<?php echo $content; ?> <p class="pull-right"><?= Yii::powered() ?></p>
</div>
<hr> </footer>
<div class="footer"> <?php $this->endBody() ?>
<p>&copy; My Company <?php echo date('Y'); ?></p>
<p>
<?php echo Yii::powered(); ?>
Template by <a href="http://twitter.github.io/bootstrap/">Twitter Bootstrap</a>
</p>
</div>
<?php $this->endBody(); ?>
</div>
<?php echo Toolbar::widget(); ?>
</body> </body>
</html> </html>
<?php $this->endPage(); ?> <?php $this->endPage() ?>

14
apps/advanced/frontend/views/site/about.php

@ -1,16 +1,16 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
/** /**
* @var yii\base\View $this * @var yii\web\View $this
*/ */
$this->title = 'About'; $this->title = 'About';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-about">
<h1><?= Html::encode($this->title) ?></h1>
<p>
This is the About page. You may modify the following file to customize its content:
</p>
<code><?php echo __FILE__; ?></code> <p>This is the About page. You may modify the following file to customize its content:</p>
<code><?= __FILE__ ?></code>
</div>

57
apps/advanced/frontend/views/site/contact.php

@ -1,46 +1,39 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\widgets\Captcha; use yii\captcha\Captcha;
/** /**
* @var yii\base\View $this * @var yii\web\View $this
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model * @var app\models\ContactForm $model
*/ */
$this->title = 'Contact'; $this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-contact">
<h1><?= Html::encode($this->title) ?></h1>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?> <p>
<div class="alert alert-success"> If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
Thank you for contacting us. We will respond to you as soon as possible. </p>
</div>
<?php return; endif; ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<?php $form = ActiveForm::begin(array( <div class="row">
'options' => array('class' => 'form-horizontal'), <div class="col-lg-5">
'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), <?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
)); ?> <?= $form->field($model, 'name') ?>
<?php echo $form->field($model, 'name')->textInput(); ?> <?= $form->field($model, 'email') ?>
<?php echo $form->field($model, 'email')->textInput(); ?> <?= $form->field($model, 'subject') ?>
<?php echo $form->field($model, 'subject')->textInput(); ?> <?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?> <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
<?php 'options' => ['class' => 'form-control'],
$field = $form->field($model, 'verifyCode'); 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
echo $field->begin() ]) ?>
. $field->label() <div class="form-group">
. Captcha::widget() <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
. Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium')) </div>
. $field->error() <?php ActiveForm::end(); ?>
. $field->end(); </div>
?>
<div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?>
</div>

29
apps/advanced/frontend/views/site/error.php

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
/**
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception
*/
$this->title = $name;
?>
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>

70
apps/advanced/frontend/views/site/index.php

@ -1,47 +1,53 @@
<?php <?php
/** /**
* @var yii\base\View $this * @var yii\web\View $this
*/ */
$this->title = 'Welcome'; $this->title = 'My Yii Application';
?> ?>
<div class="jumbotron"> <div class="site-index">
<h1>Welcome!</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus <div class="jumbotron">
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> <h1>Congratulations!</h1>
<a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a>
</div>
<hr> <p class="lead">You have successfully created your Yii-powered application.</p>
<!-- Example row of columns --> <p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
<div class="row-fluid"> </div>
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris <div class="body-content">
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p> <div class="row">
</div> <div class="col-lg-4">
<div class="span4"> <h2>Heading</h2>
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
Donec sed odio dui. </p> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn" href="#">View details &raquo;</a></p> <p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation &raquo;</a></p>
</div> </div>
<div class="span4"> <div class="col-lg-4">
<h2>Heading</h2> <h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
massa.</p> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/forum/">Yii Forum &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/extensions/">Yii Extensions &raquo;</a></p>
</div>
</div>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div> </div>
</div> </div>

29
apps/advanced/frontend/views/site/login.php

@ -3,22 +3,31 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/** /**
* @var yii\base\View $this * @var yii\web\View $this
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model * @var app\models\LoginForm $model
*/ */
$this->title = 'Login'; $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p> <p>Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin(array('options' => array('class' => 'form-horizontal'))); ?> <div class="row">
<?php echo $form->field($model, 'username')->textInput(); ?> <div class="col-lg-5">
<?php echo $form->field($model, 'password')->passwordInput(); ?> <?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?> <?= $form->field($model, 'username') ?>
<div class="form-actions"> <?= $form->field($model, 'password')->passwordInput() ?>
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?> <?= $form->field($model, 'rememberMe')->checkbox() ?>
<div style="color:#999;margin:1em 0">
If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.
</div>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div> </div>
<?php ActiveForm::end(); ?> </div>

28
apps/advanced/frontend/views/site/requestPasswordResetToken.php

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
$this->title = 'Request password reset';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-request-password-reset">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out your email. A link to reset password will be sent there.</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<?= $form->field($model, 'email') ?>
<div class="form-group">
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

28
apps/advanced/frontend/views/site/resetPassword.php

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
$this->title = 'Reset password';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-reset-password">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please choose your new password:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'reset-password-form']); ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

30
apps/advanced/frontend/views/site/signup.php

@ -0,0 +1,30 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
$this->title = 'Signup';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-signup">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to signup:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?= Html::submitButton('Signup', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

0
apps/advanced/frontend/www/.gitignore → apps/advanced/frontend/web/.gitignore vendored

0
apps/advanced/frontend/www/assets/.gitignore → apps/advanced/frontend/web/assets/.gitignore vendored

45
apps/advanced/frontend/web/css/site.css

@ -0,0 +1,45 @@
body {
padding-top: 70px;
}
.footer {
border-top: 1px solid #ddd;
margin-top: 30px;
padding-top: 15px;
padding-bottom: 30px;
}
.jumbotron {
text-align: center;
background-color: transparent;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.not-set {
color: #c55;
font-style: italic;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after { content: /*"\e113"*/"\e151"; }
a.desc:after { content: /*"\e114"*/"\e152"; }
.sort-numerical a.asc:after { content: "\e153"; }
.sort-numerical a.desc:after { content: "\e154"; }
.sort-ordinal a.asc:after { content: "\e155"; }
.sort-ordinal a.desc:after { content: "\e156"; }

BIN
apps/advanced/frontend/web/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

2
apps/advanced/frontend/web/robots.txt

@ -0,0 +1,2 @@
User-agent: *
Disallow:

66
apps/advanced/frontend/widgets/Alert.php

@ -0,0 +1,66 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\widgets;
/**
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* - \Yii::$app->getSession()->setFlash('error', 'This is the message');
* - \Yii::$app->getSession()->setFlash('success', 'This is the message');
* - \Yii::$app->getSession()->setFlash('info', 'This is the message');
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcerative.ru>
*/
class Alert extends \yii\bootstrap\Widget
{
/**
* @var array the alert types configuration for the flash messages.
* This array is setup as $key => $value, where:
* - $key is the name of the session flash variable
* - $value is the bootstrap alert type (i.e. danger, success, info, warning)
*/
public $alertTypes = [
'error' => 'danger',
'danger' => 'danger',
'success' => 'success',
'info' => 'info',
'warning' => 'warning'
];
/**
* @var array the options for rendering the close button tag.
*/
public $closeButton = [];
public function init()
{
parent::init();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $message) {
/* initialize css class for each alert box */
$this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type;
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options
]);
$session->removeFlash($type);
}
}
}

78
apps/advanced/frontend/www/css/site.css

@ -1,78 +0,0 @@
body {
padding-top: 20px;
padding-bottom: 60px;
}
/* Custom container */
.container {
margin: 0 auto;
max-width: 1000px;
}
.container > hr {
margin: 60px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 80px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 100px;
line-height: 1;
}
.jumbotron .lead {
font-size: 24px;
line-height: 1.25;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
/* Supporting marketing content */
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar .navbar-inner {
padding: 0;
}
.navbar .nav {
margin: 0;
display: table;
width: 100%;
}
.navbar .nav li {
display: table-cell;
width: 1%;
float: none;
}
.navbar .nav li a {
font-weight: bold;
text-align: center;
border-left: 1px solid rgba(255, 255, 255, .75);
border-right: 1px solid rgba(0, 0, 0, .1);
}
.navbar .nav li:first-child a {
border-left: 0;
border-radius: 3px 0 0 3px;
}
.navbar .nav li:last-child a {
border-right: 0;
border-radius: 0 3px 3px 0;
}

74
apps/advanced/init

@ -1,27 +1,49 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
$params = getParams();
$root = str_replace('\\', '/', __DIR__); $root = str_replace('\\', '/', __DIR__);
$envs = require("$root/environments/index.php"); $envs = require("$root/environments/index.php");
$envNames = array_keys($envs); $envNames = array_keys($envs);
echo "Yii Application Init Tool v1.0\n\n"; echo "Yii Application Initialization Tool v1.0\n\n";
echo "Which environment do you want the application to be initialized in?\n\n";
foreach ($envNames as $i => $name) { $envName = null;
echo " [$i] $name\n"; if (empty($params['env'])) {
echo "Which environment do you want the application to be initialized in?\n\n";
foreach ($envNames as $i => $name) {
echo " [$i] $name\n";
}
echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
$answer = trim(fgets(STDIN));
if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
echo "\n Quit initialization.\n";
exit(0);
}
if (isset($envNames[$answer])) {
$envName = $envNames[$answer];
}
}
else {
$envName = $params['env'];
} }
echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
$answer = trim(fgets(STDIN)); if (!in_array($envName, $envNames)) {
if (!ctype_digit($answer) || !isset($envNames[$answer])) { $envsList = implode(', ', $envNames);
echo "\n Quit initialization.\n"; echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
return; exit(2);
} }
$env = $envs[$envNames[$answer]]; $env = $envs[$envName];
echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
$answer = trim(fgets(STDIN)); if (empty($params['env'])) {
if (strncasecmp($answer, 'y', 1)) { echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
echo "\n Quit initialization.\n"; $answer = trim(fgets(STDIN));
return; if (strncasecmp($answer, 'y', 1)) {
echo "\n Quit initialization.\n";
exit(0);
}
} }
echo "\n Start initialization ...\n\n"; echo "\n Start initialization ...\n\n";
@ -51,7 +73,7 @@ echo "\n ... initialization completed.\n\n";
function getFileList($root, $basePath = '') function getFileList($root, $basePath = '')
{ {
$files = array(); $files = [];
$handle = opendir($root); $handle = opendir($root);
while (($path = readdir($handle)) !== false) { while (($path = readdir($handle)) !== false) {
if ($path === '.svn' || $path === '.' || $path === '..') { if ($path === '.svn' || $path === '.' || $path === '..') {
@ -110,3 +132,23 @@ function copyFile($root, $source, $target, &$all)
file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
return true; return true;
} }
function getParams()
{
$rawParams = [];
if (isset($_SERVER['argv'])) {
$rawParams = $_SERVER['argv'];
array_shift($rawParams);
}
$params = [];
foreach ($rawParams as $param) {
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
$name = $matches[1];
$params[$name] = isset($matches[3]) ? $matches[3] : true;
} else {
$params[] = $param;
}
}
return $params;
}

53
apps/advanced/requirements.php

@ -26,78 +26,85 @@ $requirementsChecker = new YiiRequirementChecker();
/** /**
* Adjust requirements according to your application specifics. * Adjust requirements according to your application specifics.
*/ */
$requirements = array( $requirements = [
// Database : // Database :
array( [
'name' => 'PDO extension', 'name' => 'PDO extension',
'mandatory' => true, 'mandatory' => true,
'condition' => extension_loaded('pdo'), 'condition' => extension_loaded('pdo'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>', 'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
), ],
array( [
'name' => 'PDO SQLite extension', 'name' => 'PDO SQLite extension',
'mandatory' => false, 'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'), 'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>', 'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for SQLite database.', 'memo' => 'Required for SQLite database.',
), ],
array( [
'name' => 'PDO MySQL extension', 'name' => 'PDO MySQL extension',
'mandatory' => false, 'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'), 'condition' => extension_loaded('pdo_mysql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>', 'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for MySQL database.', 'memo' => 'Required for MySQL database.',
), ],
[
'name' => 'PDO PostgreSQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_pgsql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for PostgreSQL database.',
],
// Cache : // Cache :
array( [
'name' => 'Memcache extension', 'name' => 'Memcache extension',
'mandatory' => false, 'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'), 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>', 'by' => '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.' : '' 'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.' : ''
), ],
array( [
'name' => 'APC extension', 'name' => 'APC extension',
'mandatory' => false, 'mandatory' => false,
'condition' => extension_loaded('apc') || extension_loaded('apc'), 'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>', 'by' => '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
), ],
// Additional PHP extensions : // Additional PHP extensions :
array( [
'name' => 'Mcrypt extension', 'name' => 'Mcrypt extension',
'mandatory' => false, 'mandatory' => false,
'condition' => extension_loaded('mcrypt'), 'condition' => extension_loaded('mcrypt'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>', 'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
'memo' => 'Required by encrypt and decrypt methods.' 'memo' => 'Required by encrypt and decrypt methods.'
), ],
// PHP ini : // PHP ini :
'phpSafeMode' => array( 'phpSafeMode' => [
'name' => 'PHP safe mode', 'name' => 'PHP safe mode',
'mandatory' => false, 'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"), 'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
'by' => 'File uploading and console command execution', 'by' => 'File uploading and console command execution',
'memo' => '"safe_mode" should be disabled at php.ini', 'memo' => '"safe_mode" should be disabled at php.ini',
), ],
'phpExposePhp' => array( 'phpExposePhp' => [
'name' => 'Expose PHP', 'name' => 'Expose PHP',
'mandatory' => false, 'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"), 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons', 'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini', 'memo' => '"expose_php" should be disabled at php.ini',
), ],
'phpAllowUrlInclude' => array( 'phpAllowUrlInclude' => [
'name' => 'PHP allow url include', 'name' => 'PHP allow url include',
'mandatory' => false, 'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"), 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons', 'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini', 'memo' => '"allow_url_include" should be disabled at php.ini',
), ],
'phpSmtp' => array( 'phpSmtp' => [
'name' => 'PHP mail SMTP', 'name' => 'PHP mail SMTP',
'mandatory' => false, 'mandatory' => false,
'condition' => strlen(ini_get('SMTP'))>0, 'condition' => strlen(ini_get('SMTP'))>0,
'by' => 'Email sending', 'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required', 'memo' => 'PHP mail SMTP server required',
), ],
); ];
$requirementsChecker->checkYii()->check($requirements)->render(); $requirementsChecker->checkYii()->check($requirements)->render();

4
apps/basic/LICENSE.md

@ -1,7 +1,7 @@
The Yii framework is free software. It is released under the terms of The Yii framework is free software. It is released under the terms of
the following BSD License. the following BSD License.
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -29,4 +29,4 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.

56
apps/basic/README.md

@ -1,17 +1,12 @@
Yii 2 Basic Application Template Yii 2 Basic Application Template
================================ ================================
**NOTE** Yii 2 and the relevant applications and extensions are still under heavy Yii 2 Basic Application Template is a skeleton Yii 2 application best for
development. We may make significant changes without prior notices. Please do not rapidly developing small Websites containing mainly informational pages.
use them for production. Please consider using [Yii v1.1](https://github.com/yiisoft/yii)
if you have a project to be deployed for production soon.
The template contains the basic features including user login/logout and a contact page.
Thank you for using Yii 2 Basic Application Template - an application template It includes all commonly used configurations that would allow you to focus on adding new
that works out-of-box and can be easily customized to fit for your needs. features to your application.
Yii 2 Basic Application Template is best suitable for small Websites which mainly contain
a few informational pages.
DIRECTORY STRUCTURE DIRECTORY STRUCTURE
@ -24,53 +19,46 @@ DIRECTORY STRUCTURE
runtime/ contains files generated during runtime runtime/ contains files generated during runtime
vendor/ contains dependent 3rd-party packages vendor/ contains dependent 3rd-party packages
views/ contains view files for the Web application views/ contains view files for the Web application
www/ contains the entry script and Web resources web/ contains the entry script and Web resources
REQUIREMENTS REQUIREMENTS
------------ ------------
The minimum requirement by Yii is that your Web server supports PHP 5.3.?. The minimum requirement by this application template that your Web server supports PHP 5.4.0.
INSTALLATION INSTALLATION
------------ ------------
### Install via Composer ### Install from an Archive File
If you do not have [Composer](http://getcomposer.org/), you may download it from
[http://getcomposer.org/](http://getcomposer.org/) or run the following command on Linux/Unix/MacOS:
~~~ Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
curl -s http://getcomposer.org/installer | php a directory named `basic` that is directly under the Web root.
~~~
You can then install the Bootstrap Application using the following command: You can then access the application through the following URL:
~~~ ~~~
php composer.phar create-project --stability=dev yiisoft/yii2-app-basic yii-basic http://localhost/basic/web/
~~~ ~~~
Now you should be able to access the application using the URL `http://localhost/yii-basic/www/`,
assuming `yii-basic` is directly under the document root of your Web server.
### Install from an Archive File ### Install via Composer
This is not currently available. We will provide it when Yii 2 is formally released. If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
You can then install this application template using the following command:
### Install from development repository ~~~
php composer.phar create-project --stability=dev yiisoft/yii2-app-basic basic
~~~
If you've cloned the [Yii 2 framework main development repository](https://github.com/yiisoft/yii2) you Now you should be able to access the application through the following URL, assuming `basic` is the directory
can bootstrap your application with: directly under the Web root.
~~~ ~~~
cd yii2/apps/basic http://localhost/basic/web/
php composer.phar create-project
~~~ ~~~
*Note: If the above command fails with `[RuntimeException] Not enough arguments.` run
`php composer.phar self-update` to obtain an updated version of composer which supports creating projects
from local packages.*

1
apps/basic/assets/.gitkeep

@ -1 +0,0 @@
*

29
apps/basic/assets/AppAsset.php

@ -0,0 +1,29 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

18
apps/basic/codeception.yml

@ -0,0 +1,18 @@
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
memory_limit: 1024M
log: true
colors: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

9
apps/basic/commands/HelloController.php

@ -6,10 +6,11 @@
*/ */
namespace app\commands; namespace app\commands;
use yii\console\Controller; use yii\console\Controller;
/** /**
* This command echos what the first argument that you have entered. * This command echoes the first argument that you have entered.
* *
* This command is provided as an example for you to learn how to create console commands. * This command is provided as an example for you to learn how to create console commands.
* *
@ -19,11 +20,11 @@ use yii\console\Controller;
class HelloController extends Controller class HelloController extends Controller
{ {
/** /**
* This command echos what you have entered as the message. * This command echoes what you have entered as the message.
* @param string $message the message to be echoed. * @param string $message the message to be echoed.
*/ */
public function actionIndex($message = 'hello world') public function actionIndex($message = 'hello world')
{ {
echo $message."\n"; echo $message . "\n";
} }
} }

18
apps/basic/composer.json

@ -14,21 +14,25 @@
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.4.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "*",
"yiisoft/yii2-composer": "dev-master" "yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-swiftmailer": "*"
}, },
"scripts": { "scripts": {
"post-create-project-cmd": [ "post-create-project-cmd": [
"yii\\composer\\InstallHandler::setPermissions" "yii\\composer\\Installer::setPermission"
] ]
}, },
"extra": { "extra": {
"yii-install-writable": [ "writable": [
"runtime", "runtime",
"www/assets" "web/assets"
], ],
"yii-install-executable": [ "executable": [
"yii" "yii"
] ]
} }

164
apps/basic/composer.lock generated

@ -1,164 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "91ba258de768b93025f86071f3bb4b84",
"packages": [
{
"name": "yiisoft/yii2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-framework.git",
"reference": "3ad6334be076a80df3b2ea0b57f38bd0c6901989"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/3ad6334be076a80df3b2ea0b57f38bd0c6901989",
"reference": "3ad6334be076a80df3b2ea0b57f38bd0c6901989",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"lib-pcre": "*",
"php": ">=5.3.7"
},
"suggest": {
"ezyang/htmlpurifier": "Required by HtmlPurifier.",
"michelf/php-markdown": "Required by Markdown.",
"smarty/smarty": "Required by SmartyViewRenderer.",
"twig/twig": "Required by TwigViewRenderer."
},
"type": "library",
"autoload": {
"psr-0": {
"yii\\": "/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Qiang Xue",
"email": "qiang.xue@gmail.com",
"homepage": "http://www.yiiframework.com/",
"role": "Founder and project lead"
},
{
"name": "Alexander Makarov",
"email": "sam@rmcreative.ru",
"homepage": "http://rmcreative.ru/",
"role": "Core framework development"
},
{
"name": "Maurizio Domba",
"homepage": "http://mdomba.info/",
"role": "Core framework development"
},
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc",
"homepage": "http://cebe.cc/",
"role": "Core framework development"
},
{
"name": "Wei Zhuo",
"email": "weizhuo@gmail.com",
"role": "Project site maintenance and development"
},
{
"name": "Sebastián Thierer",
"email": "sebas@artfos.com",
"role": "Component development"
},
{
"name": "Jeffrey Winesett",
"email": "jefftulsa@gmail.com",
"role": "Documentation and marketing"
},
{
"name": "Timur Ruziev",
"email": "resurtm@gmail.com",
"homepage": "http://resurtm.com/",
"role": "Core framework development"
},
{
"name": "Paul Klimov",
"email": "klimov.paul@gmail.com",
"role": "Core framework development"
}
],
"description": "Yii2 Web Programming Framework",
"homepage": "http://www.yiiframework.com/",
"keywords": [
"framework",
"yii"
],
"time": "2013-06-02 19:19:29"
},
{
"name": "yiisoft/yii2-composer",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-composer.git",
"reference": "7ce4060faca940b836ab88de207638940a0a0568"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7ce4060faca940b836ab88de207638940a0a0568",
"reference": "7ce4060faca940b836ab88de207638940a0a0568",
"shasum": ""
},
"require": {
"yiisoft/yii2": "*"
},
"type": "library",
"autoload": {
"psr-0": {
"yii\\composer": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Qiang Xue",
"email": "qiang.xue@gmail.com",
"homepage": "http://www.yiiframework.com/",
"role": "Founder and project lead"
}
],
"description": "The composer integration for the Yii framework",
"keywords": [
"composer",
"install",
"update",
"yii"
],
"time": "2013-05-23 19:12:45"
}
],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "dev",
"stability-flags": {
"yiisoft/yii2": 20,
"yiisoft/yii2-composer": 20
},
"platform": {
"php": ">=5.3.0"
},
"platform-dev": [
]
}

18
apps/basic/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

11
apps/basic/config/codeception/acceptance.php

@ -0,0 +1,11 @@
<?php
// configuration adjustments for codeception acceptance tests. Will be merged with web.php config.
return [
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance',
],
],
];

11
apps/basic/config/codeception/functional.php

@ -0,0 +1,11 @@
<?php
// configuration adjustments for codeception functional tests. Will be merged with web.php config.
return [
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional',
],
],
];

15
apps/basic/config/codeception/unit.php

@ -0,0 +1,15 @@
<?php
// configuration adjustments for codeception unit tests. Will be merged with web.php config.
return [
'components' => [
'fixture' => [
'class' => 'yii\test\DbFixtureManager',
'basePath' => '@tests/unit/fixtures',
],
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit',
],
],
];

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save