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
# composer vendor dir
/yii/vendor
/vendor
# composer itself is not needed
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
php:
- 5.3
- 5.4
- 5.5
# - hhvm # commented until composer or hhvm get fixed: https://github.com/facebook/hhvm/issues/1347
env:
- DB=mysql
services:
- 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:
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS yiitest;'; fi"
- psql -U postgres -c 'drop database if exists yiitest;';
- psql -U postgres -c 'create database yiitest;';
script: phpunit
- echo 'elasticsearch version ' && curl http://localhost:9200/
- mysql -e 'CREATE DATABASE yiitest;';
- psql -U postgres -c 'CREATE DATABASE yiitest;';
- 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 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.
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
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
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 v1.1](https://github.com/yiisoft/yii).
Yii 2 is a complete rewrite of its previous version Yii 1.1 which is one of the most popular PHP frameworks.
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)
[![Dependency Status](https://www.versioneye.com/php/yiisoft:yii2/dev-master/badge.png)](https://www.versioneye.com/php/yiisoft:yii2/dev-master)
DIRECTORY STRUCTURE
-------------------
apps/ ready-to-use Web apps built on Yii 2
basic/ a simple app supporting user login and contact page
apps/ ready-to-use application templates
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
docs/ documentation
yii/ framework source files
extensions/ extensions
framework/ core framework code
tests/ tests of the core framework code
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
-------------
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)
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
------------------
@ -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.
- 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 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.
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
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
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
===================================
**NOTE** Yii 2 and the relevant applications and extensions are still under heavy
development. We may make significant changes without prior notices. Please do not
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.
Yii 2 Advanced Application Template is a skeleton Yii 2 application best for
developing complex Web applications with multiple tiers.
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
that works out-of-box and can be easily customized to fit for your needs.
Yii 2 Advanced Application Template is best suitable for large projects requiring frontend and backend separation,
deployment in different environments, configuration nesting etc.
The template is designed to work in a team development environment. It supports
deploying the application in different environments.
DIRECTORY STRUCTURE
@ -34,7 +31,7 @@ backend
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
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
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
@ -42,57 +39,40 @@ frontend
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
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
environments/ contains environment-based overrides
```
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
------------
### Install via Composer
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
~~~
### Install from an Archive File
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
can bootstrap your application with:
You can then install the application using the following command:
~~~
cd yii2/apps/advanced
php composer.phar create-project
php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced advanced
~~~
*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
---------------
@ -100,14 +80,11 @@ GETTING STARTED
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.
1. Execute the `init` command and select `dev` as environment.
2. Create a new database. It is assumed that MySQL InnoDB is used. If not, adjust `console/migrations/m130524_201442_init.php`.
3. In `common/config/params.php` set your database details in `components.db` values.
1. Run command `init` to initialize the application with a specific environment.
2. Create a new database and adjust the `components.db` configuration in `common/config/params.php` accordingly.
3. Run command `yii migrate` to apply DB migrations.
Now you should be able to access:
- the frontend using the URL `http://localhost/yii-advanced/frontend/www/`
- the backend using the URL `http://localhost/yii-advanced/backend/www/`
assuming `yii-advanced` is directly under the document root of your Web server.
- the frontend using the URL `http://localhost/advanced/frontend/web/`
- the backend using the URL `http://localhost/advanced/backend/web/`

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

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

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

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

@ -8,26 +8,59 @@ use common\models\LoginForm;
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()
{
echo $this->render('index');
return $this->render('index');
}
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) {
Yii::$app->response->redirect(array('site/index'));
if ($model->load($_POST) && $model->login()) {
return $this->goBack();
} else {
echo $this->render('login', array(
return $this->render('login', [
'model' => $model,
));
]);
}
}
public function actionLogout()
{
Yii::$app->getUser()->logout();
Yii::$app->getResponse()->redirect(array('site/index'));
Yii::$app->user->logout();
return $this->goHome();
}
}

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

@ -1,64 +1,64 @@
<?php
use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use yii\debug\Toolbar;
/**
* @var $this \yii\base\View
* @var $content string
* @var \yii\web\View $this
* @var string $content
*/
$this->registerAssetBundle('app');
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="en">
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="utf-8"/>
<title><?php echo Html::encode($this->title); ?></title>
<?php $this->head(); ?>
<meta charset="<?= Yii::$app->charset ?>"/>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<div class="container">
<?php $this->beginBody(); ?>
<div class="masthead">
<h3 class="muted">My Company</h3>
<?php $this->beginBody() ?>
<?php
NavBar::begin([
'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="navbar-inner">
<div class="container">
<?php echo Menu::widget(array(
'options' => array('class' => 'nav'),
'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 class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= $content ?>
</div>
<?php echo Breadcrumbs::widget(array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
<hr>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>
<div class="footer">
<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(); ?>
<?php $this->endBody() ?>
</body>
</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
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'Welcome';
$this->title = 'My Yii Application';
?>
<div class="jumbotron">
<h1>Welcome!</h1>
<div class="site-index">
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a>
</div>
<div class="jumbotron">
<h1>Congratulations!</h1>
<hr>
<p class="lead">You have successfully created your Yii-powered application.</p>
<!-- Example row of columns -->
<div class="row-fluid">
<div class="span4">
<h2>Heading</h2>
<p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
</div>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<div class="body-content">
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<div class="row">
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<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" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta
felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum
massa.</p>
<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/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>

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

@ -3,22 +3,28 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model
*/
$this->title = 'Login';
$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'))); ?>
<?php echo $form->field($model, 'username')->textInput(); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</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
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',
'supportEmail' => 'support@example.com',
'components.cache' => array(
'components.cache' => [
'class' => 'yii\caching\FileCache',
),
],
'components.mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mails',
],
'components.db' => array(
'components.db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'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 $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return array(
return [
// username and password are both required
array('username, password', 'required'),
[['username', 'password'], 'required'],
// password is validated by validatePassword()
array('password', 'validatePassword'),
['password', 'validatePassword'],
// rememberMe must be a boolean value
array('rememberMe', 'boolean'),
);
['rememberMe', 'boolean'],
];
}
/**
@ -35,7 +37,7 @@ class LoginForm extends Model
*/
public function validatePassword()
{
$user = User::findByUsername($this->username);
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
@ -48,11 +50,22 @@ class LoginForm extends Model
public function login()
{
if ($this->validate()) {
$user = User::findByUsername($this->username);
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
return true;
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
} else {
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;
use yii\db\ActiveRecord;
use yii\helpers\SecurityHelper;
use yii\web\Identity;
use yii\helpers\Security;
use yii\web\IdentityInterface;
/**
* Class User
@ -12,6 +12,7 @@ use yii\web\Identity;
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $role
@ -19,7 +20,7 @@ use yii\web\Identity;
* @property integer $create_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
@ -33,79 +34,108 @@ class User extends ActiveRecord implements Identity
public function behaviors()
{
return array(
'timestamp' => array(
return [
'timestamp' => [
'class' => 'yii\behaviors\AutoTimestamp',
'attributes' => array(
ActiveRecord::EVENT_BEFORE_INSERT => array('create_time', 'update_time'),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', '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)
{
return static::find($id);
}
/**
* Finds user by username
*
* @param string $username
* @return null|User
*/
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()
{
return $this->id;
}
/**
* @return string current user auth key
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @param string $authKey
* @return boolean if auth key is valid for current user
*/
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)
{
return SecurityHelper::validatePassword($password, $this->password_hash);
return Security::validatePassword($password, $this->password_hash);
}
public function rules()
{
return array(
array('username', 'filter', 'filter' => 'trim'),
array('username', 'required'),
array('username', 'length', 'min' => 2, 'max' => 255),
array('email', 'filter', 'filter' => 'trim'),
array('email', 'required'),
array('email', 'email'),
array('email', 'unique', 'message' => 'This email address has already been taken.'),
array('password', 'required'),
array('password', 'length', 'min' => 6),
);
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'],
['email', 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'],
['password', 'required'],
['password', 'string', 'min' => 6],
];
}
public function scenarios()
{
return array(
'signup' => array('username', 'email', 'password'),
'login' => array('username', 'password'),
);
return [
'signup' => ['username', 'email', 'password'],
'resetPassword' => ['password'],
'requestPasswordResetToken' => ['email'],
];
}
public function beforeSave($insert)
{
if(parent::beforeSave($insert)) {
if($this->isNewRecord) {
if(!empty($this->password)) {
$this->password_hash = SecurityHelper::generatePasswordHash($this->password);
}
if (parent::beforeSave($insert)) {
if (($this->isNewRecord || $this->getScenario() === 'resetPassword') && !empty($this->password)) {
$this->password_hash = Security::generatePasswordHash($this->password);
}
if ($this->isNewRecord) {
$this->auth_key = Security::generateRandomKey();
}
return true;
}

17
apps/advanced/composer.json

@ -14,25 +14,28 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-composer": "dev-master"
"php": ">=5.4.0",
"yiisoft/yii2": "*",
"yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\InstallHandler::setPermissions"
"yii\\composer\\Installer::setPermission"
]
},
"extra": {
"yii-install-writable": [
"writable": [
"backend/runtime",
"backend/www/assets",
"backend/web/assets",
"console/runtime",
"console/migrations",
"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')
);
return array(
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'preload' => array('log'),
'controllerNamespace' => 'console\controllers',
'modules' => array(
),
'components' => array(
'modules' => [
],
'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'log' => array(
'class' => 'yii\logging\Router',
'targets' => array(
array(
'class' => 'yii\logging\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
),
'mail' => $params['components.mail'],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
);
];

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

@ -1,5 +1,4 @@
<?php
return array(
return [
'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()
{
// MySQL-specific table options. Adjust if you plan working with another DBMS
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
$tableOptions = null;
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,
'username' => Schema::TYPE_STRING.' NOT NULL',
'password_hash' => Schema::TYPE_STRING.' NOT NULL',
'email' => Schema::TYPE_STRING.' NOT NULL',
'role' => 'tinyint NOT NULL DEFAULT 10',
'username' => Schema::TYPE_STRING . ' NOT NULL',
'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
'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',
'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
), $tableOptions);
], $tableOptions);
}
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
return array(
);
return [
];

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

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

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

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

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

@ -1,17 +1,11 @@
<?php
return array(
'modules' => array(
// 'debug' => array(
return [
'preload' => [
//'debug',
],
'modules' => [
// 'debug' => [
// '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
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_ENV') or define('YII_ENV', 'dev');
// fcgi doesn't have STDIN defined by default
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/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'),
@ -22,4 +23,5 @@ $config = yii\helpers\ArrayHelper::merge(
);
$application = new yii\console\Application($config);
$application->run();
$exitCode = $application->run();
exit($exitCode);

44
apps/advanced/environments/index.php

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

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

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

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

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

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

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

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

@ -1,3 +1,3 @@
<?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_ENV') or define('YII_ENV', 'prod');
// fcgi doesn't have STDIN defined by default
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/yiisoft/yii2/yii/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'),
@ -22,4 +23,5 @@ $config = yii\helpers\ArrayHelper::merge(
);
$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')
);
return array(
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'preload' => array('log'),
'vendorPath' => $rootDir . '/vendor',
'controllerNamespace' => 'frontend\controllers',
'modules' => array(
),
'components' => array(
'modules' => [
'gii' => 'yii\gii\Module'
],
'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'user' => array(
'class' => 'yii\web\User',
'mail' => $params['components.mail'],
'user' => [
'identityClass' => 'common\models\User',
),
'assetManager' => array(
'bundles' => require(__DIR__ . '/assets.php'),
),
'log' => array(
'class' => 'yii\logging\Router',
'targets' => array(
array(
'class' => 'yii\logging\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
),
'enableAutoLogin' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
],
'params' => $params,
);
];

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

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

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

@ -6,56 +6,166 @@ use Yii;
use yii\web\Controller;
use common\models\LoginForm;
use frontend\models\ContactForm;
use common\models\User;
use yii\web\BadRequestHttpException;
use yii\helpers\Security;
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()
{
return array(
'captcha' => array(
'class' => 'yii\web\CaptchaAction',
),
);
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionIndex()
{
echo $this->render('index');
return $this->render('index');
}
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) {
Yii::$app->response->redirect(array('site/index'));
if ($model->load($_POST) && $model->login()) {
return $this->goBack();
} else {
echo $this->render('login', array(
return $this->render('login', [
'model' => $model,
));
]);
}
}
public function actionLogout()
{
Yii::$app->getUser()->logout();
Yii::$app->getResponse()->redirect(array('site/index'));
Yii::$app->user->logout();
return $this->goHome();
}
public function actionContact()
{
$model = new ContactForm;
if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
Yii::$app->response->refresh();
if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
return $this->refresh();
} else {
echo $this->render('contact', array(
return $this->render('contact', [
'model' => $model,
));
]);
}
}
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;
use Yii;
use yii\base\Model;
/**
@ -20,14 +21,14 @@ class ContactForm extends Model
*/
public function rules()
{
return array(
return [
// 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
array('email', 'email'),
['email', 'email'],
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha'),
);
['verifyCode', 'captcha'],
];
}
/**
@ -35,9 +36,9 @@ class ContactForm extends Model
*/
public function attributeLabels()
{
return array(
return [
'verifyCode' => 'Verification Code',
);
];
}
/**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email)
{
if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?=';
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?=';
$headers = "From: $name <{$this->email}>\r\n" .
"Reply-To: {$this->email}\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";
mail($email, $subject, $this->body, $headers);
Yii::$app->mail->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
} else {
return false;

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

@ -1,66 +1,69 @@
<?php
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use yii\debug\Toolbar;
use frontend\assets\AppAsset;
use frontend\widgets\Alert;
/**
* @var $this \yii\base\View
* @var $content string
* @var \yii\web\View $this
* @var string $content
*/
$this->registerAssetBundle('app');
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="en">
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="utf-8"/>
<title><?php echo Html::encode($this->title); ?></title>
<?php $this->head(); ?>
<meta charset="<?= Yii::$app->charset ?>"/>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<div class="container">
<?php $this->beginBody(); ?>
<div class="masthead">
<h3 class="muted">My Company</h3>
<?php $this->beginBody() ?>
<?php
NavBar::begin([
'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="navbar-inner">
<div class="container">
<?php echo Menu::widget(array(
'options' => array('class' => 'nav'),
'items' => array(
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 class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
<?php echo Breadcrumbs::widget(array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
<hr>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>
<div class="footer">
<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(); ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage(); ?>
<?php $this->endPage() ?>

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

@ -1,16 +1,16 @@
<?php
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<h1><?php echo Html::encode($this->title); ?></h1>
<p>
This is the About page. You may modify the following file to customize its content:
</p>
<div class="site-about">
<h1><?= Html::encode($this->title) ?></h1>
<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
use yii\helpers\Html;
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 app\models\ContactForm $model
*/
$this->title = 'Contact';
$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')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</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>
<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(
'options' => array('class' => 'form-horizontal'),
'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')),
)); ?>
<?php echo $form->field($model, 'name')->textInput(); ?>
<?php echo $form->field($model, 'email')->textInput(); ?>
<?php echo $form->field($model, 'subject')->textInput(); ?>
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
<?php
$field = $form->field($model, 'verifyCode');
echo $field->begin()
. $field->label()
. Captcha::widget()
. Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium'))
. $field->error()
. $field->end();
?>
<div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'options' => ['class' => 'form-control'],
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</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
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'Welcome';
$this->title = 'My Yii Application';
?>
<div class="jumbotron">
<h1>Welcome!</h1>
<div class="site-index">
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a>
</div>
<div class="jumbotron">
<h1>Congratulations!</h1>
<hr>
<p class="lead">You have successfully created your Yii-powered application.</p>
<!-- Example row of columns -->
<div class="row-fluid">
<div class="span4">
<h2>Heading</h2>
<p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
</div>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<div class="body-content">
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<div class="row">
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod.
Donec sed odio dui. </p>
<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" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta
felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum
massa.</p>
<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/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>

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

@ -3,22 +3,31 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model
*/
$this->title = 'Login';
$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'))); ?>
<?php echo $form->field($model, 'username')->textInput(); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $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>
<?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
<?php
$params = getParams();
$root = str_replace('\\', '/', __DIR__);
$envs = require("$root/environments/index.php");
$envNames = array_keys($envs);
echo "Yii Application Init Tool v1.0\n\n";
echo "Which environment do you want the application to be initialized in?\n\n";
foreach ($envNames as $i => $name) {
echo " [$i] $name\n";
echo "Yii Application Initialization Tool v1.0\n\n";
$envName = null;
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 (!ctype_digit($answer) || !isset($envNames[$answer])) {
echo "\n Quit initialization.\n";
return;
if (!in_array($envName, $envNames)) {
$envsList = implode(', ', $envNames);
echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
exit(2);
}
$env = $envs[$envNames[$answer]];
echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
$answer = trim(fgets(STDIN));
if (strncasecmp($answer, 'y', 1)) {
echo "\n Quit initialization.\n";
return;
$env = $envs[$envName];
if (empty($params['env'])) {
echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
$answer = trim(fgets(STDIN));
if (strncasecmp($answer, 'y', 1)) {
echo "\n Quit initialization.\n";
exit(0);
}
}
echo "\n Start initialization ...\n\n";
@ -51,7 +73,7 @@ echo "\n ... initialization completed.\n\n";
function getFileList($root, $basePath = '')
{
$files = array();
$files = [];
$handle = opendir($root);
while (($path = readdir($handle)) !== false) {
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));
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.
*/
$requirements = array(
$requirements = [
// Database :
array(
[
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
),
array(
],
[
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for SQLite database.',
),
array(
],
[
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'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 :
array(
[
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'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>.' : ''
),
array(
],
[
'name' => 'APC extension',
'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>',
),
],
// Additional PHP extensions :
array(
[
'name' => 'Mcrypt extension',
'mandatory' => false,
'condition' => extension_loaded('mcrypt'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
'memo' => 'Required by encrypt and decrypt methods.'
),
],
// PHP ini :
'phpSafeMode' => array(
'phpSafeMode' => [
'name' => 'PHP safe mode',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
'by' => 'File uploading and console command execution',
'memo' => '"safe_mode" should be disabled at php.ini',
),
'phpExposePhp' => array(
],
'phpExposePhp' => [
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
],
'phpAllowUrlInclude' => [
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
),
'phpSmtp' => array(
],
'phpSmtp' => [
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP'))>0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
),
);
],
];
$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 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.
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
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
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
================================
**NOTE** Yii 2 and the relevant applications and extensions are still under heavy
development. We may make significant changes without prior notices. Please do not
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.
Yii 2 Basic Application Template is a skeleton Yii 2 application best for
rapidly developing small Websites containing mainly informational pages.
Thank you for using Yii 2 Basic Application Template - an application template
that works out-of-box and can be easily customized to fit for your needs.
Yii 2 Basic Application Template is best suitable for small Websites which mainly contain
a few informational pages.
The template contains the basic features including user login/logout and a contact page.
It includes all commonly used configurations that would allow you to focus on adding new
features to your application.
DIRECTORY STRUCTURE
@ -24,53 +19,46 @@ DIRECTORY STRUCTURE
runtime/ contains files generated during runtime
vendor/ contains dependent 3rd-party packages
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
------------
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
------------
### Install via Composer
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:
### Install from an Archive File
~~~
curl -s http://getcomposer.org/installer | php
~~~
Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
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
can bootstrap your application with:
Now you should be able to access the application through the following URL, assuming `basic` is the directory
directly under the Web root.
~~~
cd yii2/apps/basic
php composer.phar create-project
http://localhost/basic/web/
~~~
*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;
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.
*
@ -19,11 +20,11 @@ use yii\console\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.
*/
public function actionIndex($message = 'hello world')
{
echo $message."\n";
echo $message . "\n";
}
}
}

18
apps/basic/composer.json

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