Browse Source

Merge branch 'master' of github.com:yiisoft/yii2 into email-swift-2

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
f77a047273
  1. 4
      LICENSE.md
  2. 4
      apps/advanced/LICENSE.md
  3. 2
      apps/advanced/backend/config/main.php
  4. 7
      apps/advanced/backend/controllers/SiteController.php
  5. 2
      apps/advanced/backend/views/layouts/main.php
  6. 2
      apps/advanced/backend/views/site/error.php
  7. 2
      apps/advanced/backend/views/site/index.php
  8. 2
      apps/advanced/backend/views/site/login.php
  9. 6
      apps/advanced/common/config/params.php
  10. 4
      apps/advanced/composer.json
  11. 2
      apps/advanced/console/config/main.php
  12. 2
      apps/advanced/frontend/config/main.php
  13. 8
      apps/advanced/frontend/controllers/SiteController.php
  14. 2
      apps/advanced/frontend/views/emails/passwordResetToken.php
  15. 2
      apps/advanced/frontend/views/layouts/main.php
  16. 2
      apps/advanced/frontend/views/site/about.php
  17. 2
      apps/advanced/frontend/views/site/contact.php
  18. 2
      apps/advanced/frontend/views/site/error.php
  19. 2
      apps/advanced/frontend/views/site/index.php
  20. 2
      apps/advanced/frontend/views/site/login.php
  21. 2
      apps/advanced/frontend/views/site/requestPasswordResetToken.php
  22. 2
      apps/advanced/frontend/views/site/resetPassword.php
  23. 2
      apps/advanced/frontend/views/site/signup.php
  24. 4
      apps/advanced/init
  25. 4
      apps/basic/LICENSE.md
  26. 4
      apps/basic/composer.json
  27. 2
      apps/basic/config/console.php
  28. 2
      apps/basic/config/web.php
  29. 11
      apps/basic/controllers/SiteController.php
  30. 2
      apps/basic/views/layouts/main.php
  31. 2
      apps/basic/views/site/about.php
  32. 2
      apps/basic/views/site/contact.php
  33. 2
      apps/basic/views/site/error.php
  34. 2
      apps/basic/views/site/index.php
  35. 2
      apps/basic/views/site/login.php
  36. 4
      apps/benchmark/LICENSE.md
  37. 2
      docs/api/db/ActiveRecord.md
  38. 68
      docs/guide/authentication.md
  39. 124
      docs/guide/authorization.md
  40. 76
      docs/guide/composer.md
  41. 2
      docs/guide/configuration.md
  42. 11
      docs/guide/debugger.md
  43. 87
      docs/guide/form.md
  44. 9
      docs/guide/i18n.md
  45. 1
      docs/guide/index.md
  46. 78
      docs/guide/installation.md
  47. 61
      docs/guide/mvc.md
  48. 2
      docs/guide/query-builder.md
  49. 8
      docs/guide/security.md
  50. 2
      docs/guide/template.md
  51. 9
      docs/guide/upgrade-from-v1.md
  52. 48
      docs/guide/url.md
  53. 2
      docs/guide/validation.md
  54. 6
      docs/guide/view.md
  55. 0
      extensions/bootstrap/Alert.php
  56. 2
      extensions/bootstrap/BootstrapAsset.php
  57. 2
      extensions/bootstrap/BootstrapPluginAsset.php
  58. 2
      extensions/bootstrap/BootstrapThemeAsset.php
  59. 0
      extensions/bootstrap/Button.php
  60. 0
      extensions/bootstrap/ButtonDropdown.php
  61. 0
      extensions/bootstrap/ButtonGroup.php
  62. 0
      extensions/bootstrap/Carousel.php
  63. 0
      extensions/bootstrap/Collapse.php
  64. 0
      extensions/bootstrap/Dropdown.php
  65. 0
      extensions/bootstrap/Modal.php
  66. 0
      extensions/bootstrap/Nav.php
  67. 0
      extensions/bootstrap/NavBar.php
  68. 0
      extensions/bootstrap/Progress.php
  69. 32
      extensions/bootstrap/README.md
  70. 0
      extensions/bootstrap/Tabs.php
  71. 0
      extensions/bootstrap/Widget.php
  72. 20
      extensions/bootstrap/composer.json
  73. 60
      extensions/composer/Installer.php
  74. 2
      extensions/composer/LICENSE.md
  75. 5
      extensions/composer/Plugin.php
  76. 91
      extensions/composer/README.md
  77. 1
      extensions/composer/composer.json
  78. 0
      extensions/debug/DebugAsset.php
  79. 0
      extensions/debug/LogTarget.php
  80. 2
      extensions/debug/Module.php
  81. 0
      extensions/debug/Panel.php
  82. 46
      extensions/debug/README.md
  83. 0
      extensions/debug/assets/main.css
  84. 23
      extensions/debug/composer.json
  85. 0
      extensions/debug/controllers/DefaultController.php
  86. 0
      extensions/debug/panels/ConfigPanel.php
  87. 0
      extensions/debug/panels/DbPanel.php
  88. 0
      extensions/debug/panels/LogPanel.php
  89. 0
      extensions/debug/panels/ProfilingPanel.php
  90. 0
      extensions/debug/panels/RequestPanel.php
  91. 2
      extensions/debug/views/default/index.php
  92. 0
      extensions/debug/views/default/toolbar.css
  93. 0
      extensions/debug/views/default/toolbar.js
  94. 2
      extensions/debug/views/default/toolbar.php
  95. 2
      extensions/debug/views/default/view.php
  96. 2
      extensions/debug/views/layouts/main.php
  97. 6
      extensions/gii/CodeFile.php
  98. 15
      extensions/gii/Generator.php
  99. 2
      extensions/gii/GiiAsset.php
  100. 0
      extensions/gii/Module.php
  101. Some files were not shown because too many files have changed in this diff Show More

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.

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.

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

@ -15,7 +15,7 @@ return [
'preload' => ['log'],
'controllerNamespace' => 'backend\controllers',
'modules' => [],
'extensions' => require(__DIR__ . '/../../vendor/yii-extensions.php'),
'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,

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

@ -15,9 +15,8 @@ class SiteController extends Controller
'class' => \yii\web\AccessControl::className(),
'rules' => [
[
'actions' => ['login'],
'actions' => ['login', 'error'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout', 'index'],
@ -45,6 +44,10 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goHome();

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

@ -6,7 +6,7 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
/**
* @var $this \yii\base\View
* @var $this \yii\web\View
* @var $content string
*/
AppAsset::register($this);

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

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception

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

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

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

@ -3,7 +3,7 @@ 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
*/

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

@ -1,8 +1,8 @@
<?php
Yii::setAlias('common', __DIR__ . '/../');
Yii::setAlias('frontend', __DIR__ . '/../../frontend');
Yii::setAlias('backend', __DIR__ . '/../../backend');
Yii::setAlias('common', realpath(__DIR__ . '/../'));
Yii::setAlias('frontend', realpath(__DIR__ . '/../../frontend'));
Yii::setAlias('backend', realpath(__DIR__ . '/../../backend'));
return [
'adminEmail' => 'admin@example.com',

4
apps/advanced/composer.json

@ -16,7 +16,9 @@
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-composer": "dev-master"
"yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master"
},
"scripts": {
"post-create-project-cmd": [

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

@ -15,7 +15,7 @@ return [
'controllerNamespace' => 'console\controllers',
'modules' => [
],
'extensions' => require(__DIR__ . '/../../vendor/yii-extensions.php'),
'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'],
'cache' => $params['components.cache'],

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

@ -16,7 +16,7 @@ return [
'modules' => [
'gii' => 'yii\gii\Module'
],
'extensions' => require(__DIR__ . '/../../vendor/yii-extensions.php'),
'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,

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

@ -17,10 +17,10 @@ class SiteController extends Controller
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => ['login', 'logout', 'signup'],
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['login', 'signup'],
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
@ -54,6 +54,10 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goHome();

2
apps/advanced/frontend/views/emails/passwordResetToken.php

@ -2,7 +2,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var common\models\User $user;
*/

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

@ -7,7 +7,7 @@ use yii\widgets\Breadcrumbs;
use frontend\widgets\Alert;
/**
* @var $this \yii\base\View
* @var $this \yii\web\View
* @var $content string
*/
AppAsset::register($this);

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

@ -2,7 +2,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;

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

@ -4,7 +4,7 @@ use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
*/

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

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception

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

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

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

@ -3,7 +3,7 @@ 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
*/

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

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/

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

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/

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

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/

4
apps/advanced/init

@ -18,7 +18,7 @@ if (empty($params['env'])) {
if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
echo "\n Quit initialization.\n";
exit(1);
exit(0);
}
if (isset($envNames[$answer])) {
@ -42,7 +42,7 @@ if (empty($params['env'])) {
$answer = trim(fgets(STDIN));
if (strncasecmp($answer, 'y', 1)) {
echo "\n Quit initialization.\n";
exit(1);
exit(0);
}
}

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.

4
apps/basic/composer.json

@ -16,7 +16,9 @@
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-composer": "dev-master"
"yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master"
},
"scripts": {
"post-create-project-cmd": [

2
apps/basic/config/console.php

@ -6,7 +6,7 @@ return [
'preload' => ['log'],
'controllerPath' => dirname(__DIR__) . '/commands',
'controllerNamespace' => 'app\commands',
'extensions' => require(__DIR__ . '/../vendor/yii-extensions.php'),
'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',

2
apps/basic/config/web.php

@ -3,7 +3,7 @@ $params = require(__DIR__ . '/params.php');
$config = [
'id' => 'bootstrap',
'basePath' => dirname(__DIR__),
'extensions' => require(__DIR__ . '/../vendor/yii-extensions.php'),
'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,

11
apps/basic/controllers/SiteController.php

@ -16,14 +16,9 @@ class SiteController extends Controller
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['login', 'logout'],
'only' => ['logout'],
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
@ -59,6 +54,10 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goBack();

2
apps/basic/views/layouts/main.php

@ -5,7 +5,7 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
/**
* @var $this \yii\base\View
* @var $this \yii\web\View
* @var $content string
*/
app\config\AppAsset::register($this);

2
apps/basic/views/site/about.php

@ -2,7 +2,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;

2
apps/basic/views/site/contact.php

@ -4,7 +4,7 @@ use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
*/

2
apps/basic/views/site/error.php

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception

2
apps/basic/views/site/index.php

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

2
apps/basic/views/site/login.php

@ -3,7 +3,7 @@ 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
*/

4
apps/benchmark/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.

2
docs/api/db/ActiveRecord.md

@ -1,6 +1,6 @@
ActiveRecord implements the [Active Record design pattern](http://en.wikipedia.org/wiki/Active_record).
The idea is that an ActiveRecord object is associated with a row in a database table
so object properties are mapped to colums of the corresponding database row.
so object properties are mapped to columns of the corresponding database row.
For example, a `Customer` object is associated with a row in the `tbl_customer`
table. Instead of writing raw SQL statements to access the data in the table,
you can call intuitive methods available in the corresponding ActiveRecord class

68
docs/guide/authentication.md

@ -0,0 +1,68 @@
Authentication
==============
Authentication is the act of verifying who a user is, and is the basis of the login process. Typically, authentication uses an identifier--a username or email address--and password, submitted through a form. The application then compares this information against that previously stored.
In Yii all this is done semi-automatically, leaving the developer to merely implement [[\yii\web\IdentityInterface]]. Typically, implementation is accomplished using the `User` model. You can find a full featured example in the
[advanced application template](installation.md). Below only the interface methods are listed:
```php
class User extends ActiveRecord implements IdentityInterface
{
// ...
/**
* 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);
}
/**
* @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->getAuthKey() === $authKey;
}
}
```
Two of the outlined methods are simple: `findIdentity` is provided with an ID and returns a model instance represented by that ID. The `getId` method returns the ID itself.
Two of the other methods--`getAuthKey` and `validateAuthKey`--are used to provide extra security to the "remember me" cookie. `getAuthKey` should return a string that is unique for each user. A good idea is to save this value when the user is created by using Yii's `Security::generateRandomKey()`:
```php
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = Security::generateRandomKey();
}
return true;
}
return false;
}
```
The `validateAuthKey` method just compares the `$authKey` variable, passed as parameter (itself retrieved from a cookie), with the value fetched from database.

124
docs/guide/authorization.md

@ -0,0 +1,124 @@
Authorization
=============
Authorization is the process of verifying that user has enough permissions to do something. Yii provides several methods
of controlling it.
Access control basics
---------------------
Basic access control is very simple to implement using [[\yii\web\AccessControl]]:
```php
class SiteController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => ['login', 'logout', 'signup'],
'rules' => [
[
'actions' => ['login', 'signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
// ...
```
In the code above we're attaching access control behavior to a controller. Since there's `only` option specified, it
will be applied to 'login', 'logout' and 'signup' actions only. A set of rules that are basically options for
[[\yii\web\AccessRule]] reads as follows:
- Allow all guest (not yet authenticated) users to access 'login' and 'signup' actions.
- Allow authenticated users to access 'logout' action.
Rules are checked one by one from top to bottom. If rule matches, action takes place immediately. If not, next rule is
checked. If no rules matched access is denied.
[[\yii\web\AccessRule]] is quite flexible and allows additionally to what was demonstrated checking IPs and request method
(i.e. POST, GET). If it's not enough you can specify your own check via anonymous function:
```php
class SiteController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => ['special'],
'rules' => [
[
'actions' => ['special'],
'allow' => true,
'matchCallback' => function ($rule, $action) {
return date('d-m') === '31-10';
}
],
```
Sometimes you want a custom action to be taken when access is denied. In this case you can specify `denyCallback`.
Role based access control (RBAC)
--------------------------------
Role based access control is very flexible approach to controlling access that is a perfect match for complex systems
where permissions are customizable.
In order to start using it some extra steps are required. First of all we need to configure `authManager` application
component:
```php
```
Then create permissions hierarchy.
Specify roles from RBAC in controller's access control configuration or call [[User::checkAccess()]] where appropriate.
### How it works
TBD: write about how it works with pictures :)
### Avoiding too much RBAC
In order to keep auth hierarchy simple and efficient you should avoid creating and using too much nodes. Most of the time
simple checks could be used instead. For example such code that uses RBAC:
```php
public function editArticle($id)
{
$article = Article::find($id);
if (!$article) {
throw new HttpException(404);
}
if (!\Yii::$app->user->checkAccess('edit_article', ['article' => $article])) {
throw new HttpException(403);
}
// ...
}
```
can be replaced with simpler code that doesn't use RBAC:
```php
public function editArticle($id)
{
$article = Article::find(['id' => $id, 'author_id' => \Yii::$app->user->id]);
if (!$article) {
throw new HttpException(404);
}
// ...
}
```

76
docs/guide/composer.md

@ -0,0 +1,76 @@
Composer
========
Yii2 uses Composer as its package manager. Composer is a PHP utility that can automatically handle the installation of needed libraries and
extensions, thereby keeping those third-party resources up to date while absolving you of the need to manually manage the project's dependencies.
Installing Composer
-------------------
In order to install Composer, check the official guide for your operating system:
* [Linux](http://getcomposer.org/doc/00-intro.md#installation-nix)
* [Windows](http://getcomposer.org/doc/00-intro.md#installation-windows)
All of the details can be found in the guide, but you'll either download Composer directly from [http://getcomposer.org/](http://getcomposer.org/), or run the following command:
```
curl -s http://getcomposer.org/installer | php
```
Adding more packages to your project
------------------------------------
The act of [installing a Yii application](installing.md) creates the `composer.json` file in the root directory of your project.
In this file you list the packages that your application requires. For Yii sites, the most important part of the file is `require` the section:
```
{
"require": {
"Michelf/php-markdown": ">=1.3",
"ezyang/htmlpurifier": ">=4.5.0"
}
}
```
Within the `require` section, you specify the name and version of each required package. The above example says that a version greater than or equal to 1.3 of Michaelf's PHP-Markdown package is required, as is version 4.5 or greater of Ezyang's HTMLPurifier. For details of this syntax, see the [official Composer documentation](http://getcomposer.org).
The full list of available Composer-supported PHP packages can be found at [packagist](http://packagist.org/). Any Yii extension can also be explicitly named using the syntax:
???
Once you have edited the `composer.json`, you can invoke Composer to install the identified dependencies. For the first installation of the dependencies, use this command:
```
php composer.phar install
```
This must be executed within your Yii project's directory, where the `composer.json` file can be found. Depending upon your operating system and setup, you may need to provide paths to the PHP executable and to the `composer.phar` script.
For an existing installation, you can have Composer update the dependencies using:
```
php composer.phar update
```
Again, you may need to provide specific path references.
In both cases, after some waiting, the required packages will be installed and ready to use in your Yii application. No additional configuration of those packages will be required.
FAQ
---
### Getting "You must enable the openssl extension to download files via https"
If you're using WAMP check [this answer at StackOverflow](http://stackoverflow.com/a/14265815/1106908).
### Getting "Failed to clone <URL here>, git was not found, check that it is installed and in your Path env."
Either install git or try adding `--prefer-dist` to the end of `install` or `update` command.
See also
--------
- [Official Composer documentation](http://getcomposer.org).

2
docs/guide/configuration.md

@ -36,7 +36,7 @@ return [
// ...
],
'params' => require(__DIR__ . '/params.php'),
);
];
```
In the above array keys are names of application properties. Depending on application type you can check properties of

11
docs/guide/debugger.md

@ -10,6 +10,17 @@ Installing and configuring
How to use it
-------------
Add these lines to your config file:
```
'preload' => ['debug'],
'modules' => [
'debug' => ['yii\debug\Module']
]
```
**Watch out: by default the debug module only works when browsing the website from the localhost. If you want to use it on a remote (staging) server, add the parameter allowedIPs to the config to whitelist your IP.**
Creating your own panels
------------------------

87
docs/guide/form.md

@ -1,3 +1,90 @@
Working with forms
==================
The primary way of using forms in Yii is through [[\yii\widgets\ActiveForm]]. This approach should be preferred when the form is based upon a model. Additionally, there are some useful methods in [[\yii\helpers\Html]] that are typically used for adding buttons and help text to any form.
When creating model-based forms, the first step is to define the model itself. The model can be either based upon the Active Record class, or the more generic Model class. For this login example, a generic model will be used:
```php
use yii\base\Model;
class LoginForm extends Model
{
public $username;
public $password;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
['username, password', 'required'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*/
public function validatePassword()
{
$user = User::findByUsername($this->username);
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
}
/**
* Logs in a user using the provided username and password.
* @return boolean whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
$user = User::findByUsername($this->username);
return true;
} else {
return false;
}
}
}
```
The controller will pass an instance of that model to the view, wherein the Active Form widget is used:
```php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
```
In the above code, `ActiveForm::begin()` not only creates a form instance, but also marks the beginning of the form. All of the content
placed between `ActiveForm::begin()` and `ActiveForm::end()` will be wrapped within the `<form>` tag. As with any widget, you can specify some options as to how the widget should be configured by passing an array to the `begin` method. In this case, an extra CSS class and identifying ID are passed to be used in the opening `<form>` tag.
In order to create a form element in the form, along with the element's label, and any application JavaScript validation, the `field` method of the Active Form widget is called. When the invocation of this method is echoed directly, the result is a regular (text) input. To
customize the output, you can chain additional methods to this call:
```php
<?= $form->field($model, 'password')->passwordInput() ?>
// or
<?= $form->field($model, 'username')->textInput()->hint('Please enter your name')->label('Name') ?>
```

9
docs/guide/i18n.md

@ -121,7 +121,7 @@ extension. After installing and enabling it you will be able to use extended syn
that allows you to specify formatting style.
Full reference is [available at ICU website](http://icu-project.org/apiref/icu4c/classMessageFormat.html) but since it's
a bit crypric we have our own reference below.
a bit cryptic we have our own reference below.
### Numbers
@ -232,6 +232,13 @@ for Russian:
In the above it worth mentioning that `=1` matches exactly `n = 1` while `one` matches `21` or `101`.
Note that if you are using placeholder twice and one time it's used as plural another one should be used as number else
you'll get "Inconsistent types declared for an argument: U_ARGUMENT_TYPE_MISMATCH" error:
```
Total {count, number} {count, plural, one{item} other{items}}.
```
To learn which inflection forms you should specify for your language you can referer to
[rules reference at unicode.org](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html).

1
docs/guide/index.md

@ -77,4 +77,5 @@ More
- [Performance Tuning](performance.md)
- [Managing assets](assets.md)
- [Testing](testing.md)
- [Composer](composer.md)
- [Upgrading from 1.1 to 2.0](upgrade-from-v1.md)

78
docs/guide/installation.md

@ -1,85 +1,83 @@
Installation
============
There are two ways you can install the Yii framework:
* Using [Composer](http://getcomposer.org/)
* Via manual download
Installing via Composer
-----------------------
The recommended way of installing Yii is by using [Composer](http://getcomposer.org/) package manager. If you do not
have it, you may download it from [http://getcomposer.org/](http://getcomposer.org/) or run the following command:
The recommended way to install Yii is to use the [Composer](http://getcomposer.org/) package manager. If you do not already
have Composer installed, you may download it from [http://getcomposer.org/](http://getcomposer.org/) or run the following command:
```
curl -s http://getcomposer.org/installer | php
```
Yii provides a few ready-to-use application templates. Based on your needs, you may choose one of them to bootstrap
your project.
For problems or more information, see the official Composer guide:
* [Linux](http://getcomposer.org/doc/00-intro.md#installation-nix)
* [Windows](http://getcomposer.org/doc/00-intro.md#installation-windows)
There are two application templates available:
With Composer installed, you can create a new Yii site using one of Yii's ready-to-use application templates. Based on your needs, choosing the right template can help bootstrap your project.
- [basic](https://github.com/yiisoft/yii2-app-basic) that is just a basic frontend application template.
- [advanced](https://github.com/yiisoft/yii2-app-advanced) that is a set of frontend, backend, console, common
(shared code) and environments support.
Currently, there are two application templates available:
Please refer to installation instructions on these pages. To read more about ideas behing these application templates and
proposed usage refer to [basic application template](apps-basic.md) and [advanced application template](apps-advanced.md).
- [basic](https://github.com/yiisoft/yii2-app-basic), just a basic frontend application template.
- [advanced](https://github.com/yiisoft/yii2-app-advanced), consisting of a frontend, a backend, console resources, common (shared code), and support for environments.
For installation instructions for these templates, see the above linked pages. To read more about ideas behind these application templates and
proposed usage, refer to the [basic application template](apps-basic.md) and [advanced application template](apps-advanced.md) documents.
Installing from zip
-------------------
Installation from zip mainly involves the following two steps:
Installation from a zip file involves two steps:
1. Download Yii Framework from [yiiframework.com](http://www.yiiframework.com/).
2. Unpack the Yii release file to a Web-accessible directory.
1. Downloading the Yii Framework from [yiiframework.com](http://www.yiiframework.com/).
2. Unpacking the downloaded file.
> Tip: Yii does not need to be installed under a Web-accessible directory.
A Yii application has one entry script which is usually the only file that
needs to be exposed to Web users. Other PHP scripts, including those from
Yii, should be protected from Web access; otherwise they might be exploited
by hackers.
> Tip: The Yii framework itself does not need to be installed under a web-accessible directory.
A Yii application has one entry script which is usually the only file that absolutely must be exposed to web users (i.e., placed within the web directory). Other PHP scripts, including those part of the
Yii framework, should be protected from web access to prevent possible exploitation by hackers.
Requirements
------------
After installing Yii, you may want to verify that your server satisfies
Yii's requirements. You can do so by accessing the requirement checker
script via the following URL in a Web browser:
~~~
http://hostname/path/to/yii/requirements/index.php
~~~
Yii's requirements. You can do so by running the requirement checker
script in a web browser.
Yii requires PHP 5.4.0, so the server must have PHP 5.4.0 or above installed and
available to the web server. Yii has been tested with [Apache HTTP server](http://httpd.apache.org/)
on Windows and Linux. It may also run on other Web servers and platforms,
provided PHP 5.4 is supported.
1. Copy the `requirements` folder from the downloaded Yii directory to your web directory.
2. Access `http://hostname/path/to/yii/requirements/index.php` in your browser.
Yii 2 requires PHP 5.4.0 or higher. Yii has been tested with the [Apache HTTP server](http://httpd.apache.org/) on Windows and Linux. Yii may also be usable on other web servers and platforms, provided that PHP 5.4 or higher is supported.
Recommended Apache Configuration
--------------------------------
Yii is ready to work with a default Apache web server configuration.
The `.htaccess` files in Yii framework and application folders deny
access to the restricted resources. To hide the bootstrap file (usually `index.php`)
in your URLs you can add `mod_rewrite` instructions to the `.htaccess` file
in your document root or to the virtual host configuration:
Yii is ready to work with a default Apache web server configuration. As a security measure, Yii comes with `.htaccess` files in the Yii framework and application folders to deny access to thoe restricted resources.
By default, requests for pages in a Yii-based site go through the boostrap file, usually named `index.php`, and placed in the application's root directory. The result will be URLs in the format `http://hostname/index.php/controller/action/param/value`.
To hide the bootstrap file in your URLs, add `mod_rewrite` instructions to the `.htaccess` file found in your web document root (or add the instructions to the virtual host configuration in Apache's `httpd.conf` file). The applicable instructions are:
~~~
RewriteEngine on
# if a directory or a file exists, use it directly
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
# Otherwise forward it to index.php
RewriteRule . index.php
~~~
Recommended Nginx Configuration
-------------------------------
You can use Yii with [Nginx](http://wiki.nginx.org/) and PHP with [FPM SAPI](http://php.net/install.fpm).
Here is a sample host configuration. It defines the bootstrap file and makes
Yii to catch all requests to nonexistent files, which allows us to have nice-looking URLs.
Yii can also be used with the popular [Nginx](http://wiki.nginx.org/) web server, so long it has PHP installed as an [FPM SAPI](http://php.net/install.fpm). Below is a sample host configuration for a Yii-based site on Nginx. The configuration identifies tells the server to send all requests for non-existent resources through the bootstrap file, resulting in "prettier" URLs without the need for `index.php` references.
~~~
server {
@ -107,4 +105,4 @@ server {
}
~~~
Make sure to set `cgi.fix_pathinfo=0` in php.ini to avoid many unnecessary system `stat()` calls.
When using this configuration, you should set `cgi.fix_pathinfo=0` in the `php.ini` file in order to avoid many unnecessary system `stat()` calls.

61
docs/guide/mvc.md

@ -2,17 +2,17 @@ MVC Overview
============
Yii implements the model-view-controller (MVC) design pattern, which is
widely adopted in Web programming. MVC aims to separate business logic from
user interface considerations, so that developers can more easily change
each part without affecting the other. In MVC, the model represents the
information (the data) and the business rules; the view contains elements
of the user interface such as text, form inputs; and the controller manages
the communication between the model and the view.
Besides implementing MVC, Yii also introduces a front-controller, called
`application`, which encapsulates the execution context for the processing
of a request. Application collects information about a user request and
then dispatches it to an appropriate controller for further handling.
widely adopted in web and other application programming. MVC aims to separate business logic from
user interface considerations, allowing developers to more easily change individual components of an application without affecting, or even touching, another.
In MVC, the *model* represents the
information (the data) and the business rules to which the data must adhere. The *view* contains elements
of the user interface, such as text, images, and form elements. The *controller* manages
the communication between the model and the view, acting as an agent.
Besides implementing the MVC design pattern, Yii also introduces a *front-controller*, called
`application`. The front-controller encapsulates the *execution context* for the processing of a request. This means that the front-controller collects information about a user request, and
then dispatches it to an appropriate controller for actual handling of that request. In other words, the front-controller is the primary application manager, handling all requests and delegating action accordingly.
The following diagram shows the static structure of a Yii application:
@ -22,31 +22,20 @@ The following diagram shows the static structure of a Yii application:
A Typical Workflow
------------------
The following diagram shows a typical workflow of a Yii application when
it is handling a user request:
The following diagram shows a typical workflow of a Yii application handling a user request:
![Typical workflow of a Yii application](flow.png)
1. A user makes a request with the URL `http://www.example.com/index.php?r=post/show&id=1`
and the Web server handles the request by executing the bootstrap script `index.php`.
2. The bootstrap script creates an [Application](/doc/guide/basics.application)
instance and runs it.
3. The Application obtains detailed user request information from
an [application component](/doc/guide/basics.application#application-component)
named `request`.
4. The application determines the requested [controller](/doc/guide/basics.controller)
and [action](/doc/guide/basics.controller#action) with the help
of an application component named `urlManager`. For this example, the controller
is `post`, which refers to the `PostController` class; and the action is `show`,
whose actual meaning is determined by the controller.
5. The application creates an instance of the requested controller
to further handle the user request. The controller determines that the action
`show` refers to a method named `actionShow` in the controller class. It then
creates and executes filters (e.g. access control, benchmarking) associated
with this action. The action is executed if it is allowed by the filters.
6. The action reads a `Post` [model](/doc/guide/basics.model) whose ID is `1` from the database.
7. The action renders a [view](/doc/guide/basics.view) named `show` with the `Post` model.
8. The view reads and displays the attributes of the `Post` model.
9. The view executes some [widgets](/doc/guide/basics.view#widget).
10. The view rendering result is embedded in a [layout](/doc/guide/basics.view#layout).
11. The action completes the view rendering and displays the result to the user.
1. A user makes a request of the URL `http://www.example.com/index.php?r=post/show&id=1`. The Web server handles the request by executing the bootstrap script `index.php`.
2. The bootstrap script creates an [Application](/doc/guide/basics.application) instance and runs it.
3. The Application instance obtains the detailed user request information from an [application component](/doc/guide/basics.application#application-component) named `request`.
4. The application determines which [controller](/doc/guide/basics.controller) and which [action](/doc/guide/basics.controller#action) of that controller was requested. This is accomplished with the help
of an application component named `urlManager`. For this example, the controller is `post`, which refers to the `PostController` class; and the action is `show`, whose actual meaning is determined by the controller.
5. The application creates an instance of the requested controller
to further handle the user request. The controller determines that the action `show` refers to a method named `actionShow` in the controller class. It then creates and executes filters (e.g. access control, benchmarking) associated with this action. The action is then executed, if execution is allowed by the filters (e.g., if the user has permission to execute that action).
6. The action creates a `Post` [model](/doc/guide/basics.model) instance, using the underlying database table, where the ID value of the corresponding record `1`.
7. The action renders a [view](/doc/guide/basics.view) named `show`, providing to the view the `Post` model instance.
8. The view reads the attributes of the `Post` model instance and displays the values of those attributes.
9. The view executes some [widgets](/doc/guide/basics.view#widget).
10. The view rendering result--the output from the previous steps--is embedded in a [layout](/doc/guide/basics.view#layout) to create a complete page.
11. The action completes the view rendering and displays the result to the user.

2
docs/guide/query-builder.md

@ -45,7 +45,7 @@ $query->select(['tbl_user.name AS author', 'tbl_post.title as title']) // <-- sp
->leftJoin('tbl_post', 'tbl_post.user_id = tbl_user.id'); // <-- join with another table
```
In the code above we've used `leftJoin` method to select from two related tables at the same time. Firsrt parameter
In the code above we've used `leftJoin` method to select from two related tables at the same time. First parameter
specifies table name and the second is the join condition. Query builder has the following methods to join tables:
- `innerJoin`

8
docs/guide/security.md

@ -1,6 +1,8 @@
Security
========
Good security is vital to the health and success of many websites. Unfortunately, many developers may cut corners when it comes to security due to a lack of understanding or too large of an implementation hurdle. To make your Yii-based site as secure as possible, the Yii framework has baked in several excellent, and easy to use, security features.
Hashing and verifying passwords
------------------------------
@ -28,7 +30,7 @@ if (Security::validatePassword($password, $hash)) {
```
Random data
Creating random data
-----------
Random data is useful in many cases. For example, when resetting a password via email you need to generate a token,
@ -63,9 +65,11 @@ Then when user want to read it:
$data = \yii\helpers\Security::decrypt($encryptedData, $secretWord);
```
Making sure data wasn't modified
Confirming data integrity
--------------------------------
Making sure data wasn't modified
hashData()
validateData()

2
docs/guide/template.md

@ -10,7 +10,7 @@ a custom template engines by reconfiguring this component's behavior:
[
'components' => [
'view' => [
'class' => 'yii\base\View',
'class' => 'yii\web\View',
'renderers' => [
'tpl' => [
'class' => 'yii\renderers\SmartyViewRenderer',

9
docs/guide/upgrade-from-v1.md

@ -106,6 +106,15 @@ Yii::$app->on($eventName, $handler);
Yii::$app->trigger($eventName);
```
If you need to handle all instances of a class instead of the object you can attach a handler like the following:
```php
Event::on([ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT], function ($event) {
Yii::trace(get_class($event->sender) . ' is inserted.');
});
```
The code above defines a handler that will be triggered for every Active Record object's `EVENT_AFTER_INSERT` event.
Path Alias
----------

48
docs/guide/url.md

@ -1,57 +1,61 @@
URL Management
==============
The concept of URL management in Yii fairly simple. The idea is that application uses internal routes and parameters
everywhere. Framework takes care of translating routes into URLs and back according to URL manager configuration.
This approach allows you to adjust URLs in a single config file without touching application code.
The concept of URL management in Yii fairly simple. URL management is based on the premise that the application uses internal routes and parameters
everywhere. The framework itself will then translates routes into URLs, and translate URLs into routs, according to the URL manager's configuration.
This approach allows you to change site-wide URLs merely by edited a single config file, without ever touching the application code.
Internal route
--------------
Internal routes and parameters are what you're dealing with when implementing an application using Yii.
Each controller and its action has a corresponding internal route such as `site/index`. Here `site` is referred to as
controller ID while `index` is referred to as action ID. If controller belongs to a module, internal route is prefixed
with the module ID such as `blog/post/index` for a blog module.
When implementing an application using Yii, you'll deal with internal routes and parameters. Each controller and controller action has a corresponding internal route, such as `site/index` or `user/create`. In the former, `site` is referred to as the *controller ID* while `index` is referred to as the *action ID*. In the second example, `user` is the controller ID and `create` is the action ID. If controller belongs to a *module*, the internal route is prefixed with the module ID, such as `blog/post/index` for a blog module (with `post` being the controller ID and `index` being the action ID).
Creating URLs
-------------
As was already mentioned, the most important rule is to always use URL manager to create URLs. Url manages is an
application component with `urlManager` id that is accessible both from web and console applications via
`\Yii::$app->urlManager` and has two following URL creation methods available:
The most important rule for creating URLs in your site is to always do so using the URL manager. The URL manager is an
application component with the `urlManager` ID. This component is accessible both from web and console applications via
`\Yii::$app->urlManager`. The component makes availabe the two following URL creation methods:
- createUrl($route, $params = [])
- createAbsoluteUrl($route, $params = [])
- `createUrl($route, $params = [])`
- `createAbsoluteUrl($route, $params = [])`
First one creates URL relative to the application root while the second one creates URL prefixed with protocol and
hostname. The former is suitable for internal application URLs while the latter is used when you need to create rules
for outside the website. For example, when sending emails or generating RSS feed.
The `createUrl` method creates a URL relative to the application root, such as `/index.php/site/index/`. The `createAbsoluteUrl` method creates URL prefixed with the proper protocol and
hostname: `http://www.example.com/index.php/site/index`. The former is suitable for internal application URLs, while the latter is used when you need to create rules for outside the website, such as when sending emails or generating an RSS feed.
Some examples:
```php
echo \Yii::$app->urlManager->createUrl('site/page', ['id' => 'about']);
// /index.php/site/page/id/about/
echo \Yii::$app->urlManager->createAbsoluteUrl('blog/post/index');
// http://www.example.com/index.php/blog/post/index/
```
Inside web application controller you can use its own `createUrl` shortcut method in the following forms:
The exact format of the outputted URL will depend upon how the URL manager is configured (which is the point). The above examples may also output:
* `/site/page/id/about/`
* `/index.php?r=site/page&id=about`
* `http://www.example.com/blog/post/index/`
* `http://www.example.com/index.php?r=blog/post/index`
Inside a web application controller, you can use the controller's own `createUrl` shortcut method. Unlike the global `createUrl` method, the controller version is context sensitive:
```php
echo $this->createUrl(''); // currently active route
echo $this->createUrl('view', ['id' => 'contact']); // same controller, different action
echo $this->createUrl('post/index'); // same module, different controller and action
echo $this->createUrl('/site/index'); // absolute route no matter which controller we're in
echo $this->createUrl('/site/index'); // absolute route no matter what controller is making this call
```
> **Tip**: In order to generate URL with a hashtag, for example `/index.php?r=site/page&id=100#title`, you need to
specify parameter named `#` using `$this->createUrl('post/read', ['id' => 100, '#' => 'title'])`.
specify the parameter named `#` using `$this->createUrl('post/read', ['id' => 100, '#' => 'title'])`.
Customizing URLs
----------------
By default Yii uses a query string format URLs such as `/index.php?r=news/view&id=100`. In order to make URLs
human-friendly you need to configure `urlManager` component like the following:
By default, Yii uses a query string format for URLs, such as `/index.php?r=news/view&id=100`. In order to make URLs
human-friendly (i.e., more readable), you need to configure the `urlManager` component in the application's configuration file. Enabling "pretty" URLs will convert the query string format to a directory-based format: `/index.php/news/view/id/100`. Disabling the `showScriptName` parameter means that `index.php` will not be part of the URLs. Here's the relevant part of the application's configuration file.
```php
<?php
@ -66,7 +70,7 @@ return [
];
```
Note that
Note that this configuration will only work if the web server has been properly configured for Yii, see (installation)[installation.md#recommended-apache-configuration].
### Named parameters

2
docs/guide/validation.md

@ -8,7 +8,7 @@ Standard Yii validators
-----------------------
Standard Yii validators could be specified using aliases instead of referring to class names. Here's the list of all
validators budled with Yii with their most useful properties:
validators bundled with Yii with their most useful properties:
### `boolean`: [[BooleanValidator]]

6
docs/guide/view.md

@ -38,7 +38,7 @@ Widgets
Widgets are a self-contained building blocks for your views. A widget may contain advanced logic, typically takes some
configuration and data and returns HTML. There is a good number of widgets bundled with Yii such as [active form](form.md),
breadcrumbs, menu or [wrappers around bootstrap component framework](boostrap-widgets.md). Additionally there are
breadcrumbs, menu or [wrappers around bootstrap component framework](bootstrap-widgets.md). Additionally there are
extensions providing additional widgets such as official one for jQueryUI components.
In order to use widget you need to do the following:
@ -113,7 +113,7 @@ to learn more refer to [Using template engines](template.md) section of the guid
Using View object in templates
------------------------------
An instance of `yii\base\View` component is available in view templates as `$this` variable. Using it in templates you
An instance of `yii\web\View` component is available in view templates as `$this` variable. Using it in templates you
can do many useful things including setting page title and meta, registering scripts and accessing the context.
### Setting page title
@ -342,7 +342,7 @@ Customizing View component
--------------------------
Since view is also an application component named `view` you can replace it with your own component that extends
from `yii\base\View`. It can be done via application configuration file such as `config/web.php`:
from `yii\base\View` or `yii\web\View`. It can be done via application configuration file such as `config/web.php`:
```php
return [

0
framework/yii/bootstrap/Alert.php → extensions/bootstrap/Alert.php

2
framework/yii/bootstrap/BootstrapAsset.php → extensions/bootstrap/BootstrapAsset.php

@ -15,7 +15,7 @@ use yii\web\AssetBundle;
*/
class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $sourcePath = '@vendor/twbs/bootstrap/dist';
public $css = [
'css/bootstrap.css',
];

2
framework/yii/bootstrap/BootstrapPluginAsset.php → extensions/bootstrap/BootstrapPluginAsset.php

@ -16,7 +16,7 @@ use yii\web\AssetBundle;
*/
class BootstrapPluginAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $sourcePath = '@vendor/twbs/bootstrap/dist';
public $js = [
'js/bootstrap.js',
];

2
framework/yii/bootstrap/BootstrapThemeAsset.php → extensions/bootstrap/BootstrapThemeAsset.php

@ -17,7 +17,7 @@ use yii\web\AssetBundle;
*/
class BootstrapThemeAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $sourcePath = '@vendor/twbs/bootstrap/dist';
public $css = [
'css/bootstrap-theme.css',
];

0
framework/yii/bootstrap/Button.php → extensions/bootstrap/Button.php

0
framework/yii/bootstrap/ButtonDropdown.php → extensions/bootstrap/ButtonDropdown.php

0
framework/yii/bootstrap/ButtonGroup.php → extensions/bootstrap/ButtonGroup.php

0
framework/yii/bootstrap/Carousel.php → extensions/bootstrap/Carousel.php

0
framework/yii/bootstrap/Collapse.php → extensions/bootstrap/Collapse.php

0
framework/yii/bootstrap/Dropdown.php → extensions/bootstrap/Dropdown.php

0
framework/yii/bootstrap/Modal.php → extensions/bootstrap/Modal.php

0
framework/yii/bootstrap/Nav.php → extensions/bootstrap/Nav.php

0
framework/yii/bootstrap/NavBar.php → extensions/bootstrap/NavBar.php

0
framework/yii/bootstrap/Progress.php → extensions/bootstrap/Progress.php

32
extensions/bootstrap/README.md

@ -0,0 +1,32 @@
Twitter Bootstrap Extension for Yii 2
=====================================
This is the Twitter Bootstrap extension for Yii 2. It encapsulates Bootstrap components
and plugins in terms of Yii widgets, and thus makes using Bootstrap components/plugins
in Yii applications extremely easy. For example, the following
single line of code in a view file would render a Bootstrap Progress plugin:
```php
<?= yii\bootstrap\Progress::widget(['percent' => 60, 'label' => 'test']) ?>
```
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-bootstrap "*"
```
or add
```
"yiisoft/yii2-bootstrap": "*"
```
to the require section of your `composer.json` file.

0
framework/yii/bootstrap/Tabs.php → extensions/bootstrap/Tabs.php

0
framework/yii/bootstrap/Widget.php → extensions/bootstrap/Widget.php

20
extensions/mutex/composer.json → extensions/bootstrap/composer.json

@ -1,7 +1,7 @@
{
"name": "yiisoft/yii2-mutex",
"description": "Mutual exclusion extension for the Yii framework",
"keywords": ["yii", "mutex"],
"name": "yiisoft/yii2-bootstrap",
"description": "The Twitter Bootstrap extension for the Yii framework",
"keywords": ["yii", "bootstrap"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
@ -11,17 +11,13 @@
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"authors": [
{
"name": "resurtm",
"email": "resurtm@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "*"
"yiisoft/yii2": "*",
"twbs/bootstrap": "3.0.*"
},
"autoload": {
"psr-0": { "yii\\mutex\\": "" }
}
"psr-0": { "yii\\bootstrap\\": "" }
},
"target-dir": "yii/bootstrap"
}

60
extensions/composer/yii/composer/Installer.php → extensions/composer/Installer.php

@ -11,6 +11,7 @@ use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Script\CommandEvent;
use Composer\Util\Filesystem;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
@ -22,6 +23,8 @@ class Installer extends LibraryInstaller
const EXTRA_WRITABLE = 'writable';
const EXTRA_EXECUTABLE = 'executable';
const EXTENSION_FILE = 'yiisoft/extensions.php';
/**
* @inheritdoc
*/
@ -65,8 +68,11 @@ class Installer extends LibraryInstaller
'version' => $package->getVersion(),
];
$alias = $this->generateDefaultAlias($package);
if (!empty($alias)) {
$extension['alias'] = $alias;
}
$extra = $package->getExtra();
if (isset($extra[self::EXTRA_BOOTSTRAP]) && is_string($extra[self::EXTRA_BOOTSTRAP])) {
$extension['bootstrap'] = $extra[self::EXTRA_BOOTSTRAP];
}
@ -76,6 +82,30 @@ class Installer extends LibraryInstaller
$this->saveExtensions($extensions);
}
protected function generateDefaultAlias(PackageInterface $package)
{
$autoload = $package->getAutoload();
if (empty($autoload['psr-0'])) {
return false;
}
$fs = new Filesystem;
$vendorDir = $fs->normalizePath($this->vendorDir);
$aliases = [];
foreach ($autoload['psr-0'] as $name => $path) {
$name = str_replace('\\', '/', trim($name, '\\'));
if (!$fs->isAbsolutePath($path)) {
$path = $this->vendorDir . '/' . $package->getName() . '/' . $path;
}
$path = $fs->normalizePath($path);
if (strpos($path . '/', $vendorDir . '/') === 0) {
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir)) . '/' . $name;
} else {
$aliases["@$name"] = $path . '/' . $name;
}
}
return $aliases;
}
protected function removePackage(PackageInterface $package)
{
$packages = $this->loadExtensions();
@ -85,14 +115,34 @@ class Installer extends LibraryInstaller
protected function loadExtensions()
{
$file = $this->vendorDir . '/yii-extensions.php';
return is_file($file) ? require($file) : [];
$file = $this->vendorDir . '/' . self::EXTENSION_FILE;
if (!is_file($file)) {
return [];
}
$extensions = require($file);
$vendorDir = str_replace('\\', '/', $this->vendorDir);
$n = strlen($vendorDir);
foreach ($extensions as &$extension) {
if (isset($extension['alias'])) {
foreach ($extension['alias'] as $alias => $path) {
$path = str_replace('\\', '/', $path);
if (strpos($path . '/', $vendorDir . '/') === 0) {
$extension['alias'][$alias] = '<vendor-dir>' . substr($path, $n);
}
}
}
}
return $extensions;
}
protected function saveExtensions(array $extensions)
{
$file = $this->vendorDir . '/yii-extensions.php';
file_put_contents($file, "<?php\nreturn " . var_export($extensions, true) . ";\n");
$file = $this->vendorDir . '/' . self::EXTENSION_FILE;
$array = str_replace("'<vendor-dir>", '$vendorDir . \'', var_export($extensions, true));
file_put_contents($file, "<?php\n\n\$vendorDir = dirname(__DIR__);\n\nreturn $array;\n");
}

2
extensions/composer/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

5
extensions/composer/yii/composer/Plugin.php → extensions/composer/Plugin.php

@ -26,9 +26,10 @@ class Plugin implements PluginInterface
{
$installer = new Installer($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
$file = rtrim($composer->getConfig()->get('vendor-dir'), '/') . '/yii-extensions.php';
$file = rtrim($composer->getConfig()->get('vendor-dir'), '/') . '/yiisoft/extensions.php';
if (!is_file($file)) {
file_put_contents($file, "<?php\nreturn [];\n");
@mkdir(dirname($file));
file_put_contents($file, "<?php\n\nreturn [];\n");
}
}
}

91
extensions/composer/README.md

@ -1,44 +1,63 @@
Yii 2.0 Public Preview - Composer Installer
===========================================
Yii 2 Composer Installer
========================
Thank you for choosing Yii - a high-performance component-based PHP framework.
This is the composer installer for Yii 2 extensions. It implements a new composer package type named `yii2-extension`,
which should be used by all Yii 2 extensions if they are distributed as composer packages.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
Usage
-----
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2 composer installer.
Installation
------------
This extension offers you enhanced Composer handling for your yii2-project. It will therefore require you to use Composer.
To use Yii 2 composer installer, simply set `type` to be `yii2-extension` in your `composer.json`,
like the following:
```json
{
"type": "yii2-extension",
"require": {
"yiisoft/yii2": "*"
},
...
}
```
php composer.phar require yiisoft/yii2-composer "*"
```
*Note: You might have to run `php composer.phar selfupdate` before using this extension.*
Usage & Documentation
---------------------
This extension allows you to hook to certain composer events and automate preparing your Yii2 application for further usage.
After the package is installed, the `composer.json` file has to be modified to enable this extension.
To see it in action take a look at the example apps in the repository:
- [Basic](https://github.com/suralc/yii2/blob/master/apps/basic/composer.json#L27)
- [Advanced](https://github.com/suralc/yii2/blob/extensions-readme/apps/advanced/composer.json)
However it might be useful to read through the official composer [documentation](http://getcomposer.org/doc/articles/scripts.md)
to understand what this extension can do for you and what it can't.
You may specify a bootstrap class in the `extra` section. The `init()` method of the class will be executed each time
the Yii 2 application is responding to a request. For example,
```json
{
"type": "yii2-extension",
...,
"extra": {
"bootstrap": "yii\\jui\\Extension"
}
}
```
You can also use this as a template to create your own composer additions to ease development and deployment of your app.
The `Installer` class also implements a static method `setPermission()` that can be called after
a Yii 2 projected is installed, through the `post-create-project-cmd` composer script.
The method will set specified directories or files to be writable or executable, depending on
the corresponding parameters set in the `extra` section of the `composer.json` file.
For example,
```json
{
"name": "yiisoft/yii2-app-basic",
"type": "project",
...
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::setPermission"
]
},
"extra": {
"writable": [
"runtime",
"web/assets"
],
"executable": [
"yii"
]
}
}
```

1
extensions/composer/composer.json

@ -21,6 +21,7 @@
"autoload": {
"psr-0": { "yii\\composer\\": "" }
},
"target-dir": "yii/composer",
"extra": {
"class": "yii\\composer\\Plugin"
},

0
framework/yii/debug/DebugAsset.php → extensions/debug/DebugAsset.php

0
framework/yii/debug/LogTarget.php → extensions/debug/LogTarget.php

2
framework/yii/debug/Module.php → extensions/debug/Module.php

@ -9,7 +9,7 @@ namespace yii\debug;
use Yii;
use yii\base\Application;
use yii\base\View;
use yii\web\View;
use yii\web\HttpException;
/**

0
framework/yii/debug/Panel.php → extensions/debug/Panel.php

46
extensions/debug/README.md

@ -0,0 +1,46 @@
Debug Extension for Yii 2
=========================
This extension provides a debugger for Yii 2 applications. When this extension is used,
a debugger toolbar will appear at the bottom of every page. The extension also provides
a set of standalone pages to display more detailed debug information.
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-debug "*"
```
or add
```
"yiisoft/yii2-debug": "*"
```
to the require section of your `composer.json` file.
Usage
-----
Once the extension is installed, simply modify your application configuration as follows:
```php
return [
'preload' => ['debug'],
'modules' => [
'debug' => 'yii\debug\Module',
...
],
...
];
```
You will see a debugger toolbar showing at the bottom of every page of your application.
You can click on the toolbar to see more detailed debug information.

0
framework/yii/debug/assets/main.css → extensions/debug/assets/main.css

23
extensions/debug/composer.json

@ -0,0 +1,23 @@
{
"name": "yiisoft/yii2-debug",
"description": "The debugger extension for the Yii framework",
"keywords": ["yii", "debug", "debugger"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*"
},
"autoload": {
"psr-0": { "yii\\debug\\": "" }
},
"target-dir": "yii/debug"
}

0
framework/yii/debug/controllers/DefaultController.php → extensions/debug/controllers/DefaultController.php

0
framework/yii/debug/panels/ConfigPanel.php → extensions/debug/panels/ConfigPanel.php

0
framework/yii/debug/panels/DbPanel.php → extensions/debug/panels/DbPanel.php

0
framework/yii/debug/panels/LogPanel.php → extensions/debug/panels/LogPanel.php

0
framework/yii/debug/panels/ProfilingPanel.php → extensions/debug/panels/ProfilingPanel.php

0
framework/yii/debug/panels/RequestPanel.php → extensions/debug/panels/RequestPanel.php

2
framework/yii/debug/views/default/index.php → extensions/debug/views/default/index.php

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var \yii\base\View $this
* @var \yii\web\View $this
* @var array $manifest
*/

0
framework/yii/debug/views/default/toolbar.css → extensions/debug/views/default/toolbar.css

0
framework/yii/debug/views/default/toolbar.js → extensions/debug/views/default/toolbar.js

2
framework/yii/debug/views/default/toolbar.php → extensions/debug/views/default/toolbar.php

@ -1,6 +1,6 @@
<?php
/**
* @var \yii\base\View $this
* @var \yii\web\View $this
* @var \yii\debug\Panel[] $panels
* @var string $tag
*/

2
framework/yii/debug/views/default/view.php → extensions/debug/views/default/view.php

@ -5,7 +5,7 @@ use yii\bootstrap\ButtonGroup;
use yii\helpers\Html;
/**
* @var \yii\base\View $this
* @var \yii\web\View $this
* @var array $summary
* @var string $tag
* @var array $manifest

2
framework/yii/debug/views/layouts/main.php → extensions/debug/views/layouts/main.php

@ -1,6 +1,6 @@
<?php
/**
* @var \yii\base\View $this
* @var \yii\web\View $this
* @var string $content
*/
use yii\helpers\Html;

6
framework/yii/gii/CodeFile.php → extensions/gii/CodeFile.php

@ -28,7 +28,7 @@ class CodeFile extends Object
/**
* The code file is new.
*/
const OP_NEW = 'new';
const OP_CREATE = 'create';
/**
* The code file already exists, and the new one may need to overwrite it.
*/
@ -68,7 +68,7 @@ class CodeFile extends Object
if (is_file($path)) {
$this->operation = file_get_contents($path) === $content ? self::OP_SKIP : self::OP_OVERWRITE;
} else {
$this->operation = self::OP_NEW;
$this->operation = self::OP_CREATE;
}
}
@ -79,7 +79,7 @@ class CodeFile extends Object
public function save()
{
$module = Yii::$app->controller->module;
if ($this->operation === self::OP_NEW) {
if ($this->operation === self::OP_CREATE) {
$dir = dirname($this->path);
if (!is_dir($dir)) {
$mask = @umask(0);

15
framework/yii/gii/Generator.php → extensions/gii/Generator.php

@ -11,7 +11,7 @@ use Yii;
use ReflectionClass;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\base\View;
use yii\web\View;
/**
@ -111,6 +111,17 @@ abstract class Generator extends Model
}
/**
* Returns the list of auto complete values.
* The array keys are the attribute names, and the array values are the corresponding auto complete values.
* Auto complete values can also be callable typed in order one want to make postponed data generation.
* @return array the list of auto complete values
*/
public function autoCompleteData()
{
return [];
}
/**
* Returns the message to be displayed when the newly generated code is saved successfully.
* Child classes may override this method to customize the message.
* @return string the message to be displayed when the newly generated code is saved successfully.
@ -239,7 +250,7 @@ abstract class Generator extends Model
$hasError = true;
$lines[] = "generating $relativePath\n<span class=\"error\">$error</span>";
} else {
$lines[] = $file->operation === CodeFile::OP_NEW ? " generated $relativePath" : " overwrote $relativePath";
$lines[] = $file->operation === CodeFile::OP_CREATE ? " generated $relativePath" : " overwrote $relativePath";
}
} else {
$lines[] = " skipped $relativePath";

2
framework/yii/gii/GiiAsset.php → extensions/gii/GiiAsset.php

@ -26,12 +26,14 @@ class GiiAsset extends AssetBundle
*/
public $css = [
'main.css',
'typeahead.js-bootstrap.css',
];
/**
* @inheritdoc
*/
public $js = [
'gii.js',
'typeahead.js',
];
/**
* @inheritdoc

0
framework/yii/gii/Module.php → extensions/gii/Module.php

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

Loading…
Cancel
Save