Commit 7343dbdd by Aleksandr

Merge pull request #2 from yiisoft/master

switching base
parents d4152f78 a6230b50
......@@ -15,7 +15,6 @@ env:
matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: hhvm-nightly
services:
......@@ -39,7 +38,7 @@ addons:
install:
- composer self-update && composer --version
- composer global require "fxp/composer-asset-plugin:1.0.0-beta1"
- composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
- export PATH="$HOME/.composer/vendor/bin:$PATH"
# core framework:
- composer install --prefer-dist
......
......@@ -16,37 +16,36 @@ DIRECTORY STRUCTURE
```
common
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
tests/ contains various tests for objects that are common among applications
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
console
config/ contains console configurations
controllers/ contains console controllers (commands)
migrations/ contains database migrations
models/ contains console-specific model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the console application
config/ contains console configurations
controllers/ contains console controllers (commands)
migrations/ contains database migrations
models/ contains console-specific model classes
runtime/ contains files generated during runtime
backend
assets/ contains application assets such as JavaScript and CSS
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the backend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
assets/ contains application assets such as JavaScript and CSS
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
views/ contains view files for the Web application
web/ contains the entry script and Web resources
frontend
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the frontend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
views/ contains view files for the Web application
web/ contains the entry script and Web resources
widgets/ contains frontend widgets
vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
tests contains various tests for the advanced application
codeception/ contains tests developed with Codeception PHP Testing Framework
```
......@@ -75,7 +74,7 @@ at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
You can then install the application using the following command:
~~~
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta1"
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta2"
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced advanced
~~~
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */
$this->title = 'Login';
......
......@@ -95,11 +95,7 @@ class User extends ActiveRecord implements IdentityInterface
*/
public static function findByPasswordResetToken($token)
{
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
if ($timestamp + $expire < time()) {
// token expired
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
......@@ -110,6 +106,23 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
......
......@@ -42,7 +42,10 @@ class PasswordResetRequestForm extends Model
]);
if ($user) {
$user->generatePasswordResetToken();
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
}
if ($user->save()) {
return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ContactForm */
$this->title = 'Contact';
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */
$this->title = 'Login';
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\PasswordResetRequestForm */
$this->title = 'Request password reset';
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ResetPasswordForm */
$this->title = 'Reset password';
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\SignupForm */
$this->title = 'Signup';
......
......@@ -55,7 +55,7 @@ at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
You can then install this application template using the following command:
~~~
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta1"
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta2"
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
~~~
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\ContactForm */
$this->title = 'Contact';
......
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\LoginForm */
$this->title = 'Login';
......
......@@ -78,13 +78,13 @@
"yiisoft/yii2-composer": "*",
"ezyang/htmlpurifier": "4.6.*",
"cebe/markdown": "0.9.*",
"bower-asset/jquery": "2.1.*@stable | ~2.1@stable | ~1.11@stable",
"bower-asset/jquery.inputmask": "3.1.* | ~3.1",
"bower-asset/punycode": "1.3.* | ~1.3",
"bower-asset/yii2-pjax": "2.0.* | ~2.0",
"bower-asset/bootstrap": "3.2.* | ~3.1",
"bower-asset/jquery-ui": "1.11.*@stable | ~1.11@stable",
"bower-asset/typeahead.js": "0.10.* | ~0.10"
"bower-asset/jquery": "2.1.*@stable | 1.11.*@stable",
"bower-asset/jquery.inputmask": "3.1.*",
"bower-asset/punycode": "1.3.*",
"bower-asset/yii2-pjax": "2.0.*",
"bower-asset/bootstrap": "3.2.* | 3.1.*",
"bower-asset/jquery-ui": "1.11.*@stable",
"bower-asset/typeahead.js": "0.10.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
......
......@@ -55,9 +55,9 @@ Hay que tener en cuenta que a diferencia de [[yii\base\Widget::widget()]] que de
## Creación Widgets <a name="creating-widgets"></a>
Para crear un widget, se debe extender a [[yii\base\Widget]] y sobrescribir los métodos [[yii\base\Widget::init()]] y/o [[yii\base\Widget::run()]]. Normalmente el método 'init()' debería contener el código que estandariza las propiedades del widget, mientras que el método 'run()' debería contener el código que genere la representación resultante del widget. La representación resultante pude ser "pitada" directamente o devuelta como una cadena por el método 'run()'.
Para crear un widget, se debe extender a [[yii\base\Widget]] y sobrescribir los métodos [[yii\base\Widget::init()]] y/o [[yii\base\Widget::run()]]. Normalmente el método 'init()' debería contener el código que estandariza las propiedades del widget, mientras que el método 'run()' debería contener el código que genere la representación resultante del widget. La representación resultante puede ser "pintada" directamente o devuelta como una cadena por el método 'run()'.
En el siguiente ejemplo, 'HelloWidget' codifica en HTML y muestra el contenido asignado a su propiedad 'message'. Si la propiedad no esta establecida, mostrara "Hello World" por defecto.
En el siguiente ejemplo, 'HelloWidget' codifica en HTML y muestra el contenido asignado a su propiedad 'message'. Si la propiedad no está establecida, mostrará "Hello World" por defecto.
```php
namespace app\components;
......@@ -93,7 +93,7 @@ use app\components\HelloWidget;
<?= HelloWidget::widget(['message' => 'Good morning']) ?>
```
A se muestra una variante de 'HelloWidget' obtiene el contenido contenido entre las llamadas 'begin()' y 'end()', lo codifica en HTML y posteriormente lo muestra.
Abajo se muestra una variante de 'HelloWidget' obtiene el contenido entre las llamadas 'begin()' y 'end()', lo codifica en HTML y posteriormente lo muestra.
```php
namespace app\components;
......@@ -119,7 +119,7 @@ class HelloWidget extends Widget
Como se puede observar, el búfer de salida PHP es iniciado en 'init()' por tanto cualquier salida entre las llamadas de 'init()' y 'run()' puede ser capturada, procesada y devuelta en 'run()'.
>Info: Cuando se llama a [[yii\base\Widget::begin()]], se creara una nueva instancia del widget y el método 'init()' sera llamado al final del constructor del widget. Cuando se llama [[yii\base\Widget::end()]], el método 'run()' será llamado el resultado que devuelva sera escrito por 'end()'.
>Info: Cuando se llama a [[yii\base\Widget::begin()]], se creará una nueva instancia del widget y el método 'init()' será llamado al final del constructor del widget. Cuando se llama [[yii\base\Widget::end()]], el método 'run()' será llamado el resultado que devuelva será escrito por 'end()'.
El siguiente código muestra como usar esta nueva variante de 'HelloWidget':
......@@ -143,15 +143,15 @@ public function run()
}
```
Por defecto, las vistas para un widget deberían encontrarse en ficheros dentro del directorio 'WidgetPath/views', donde 'WidgetPath' representa el directorio que contiene el fichero de clase del widget. Por lo tanto, el anterior ejemplo representara el fichero de vista `@app/components/views/hello.php`, asumiendo que la clase del widget se encuentre en `@app/components`. Se puede sobrescribir el método [[yii\base\Widget::getViewPath()]] para personalizar el directorio que contenga los ficheros de vista del widget.
Por defecto, las vistas para un widget deberían encontrarse en ficheros dentro del directorio 'WidgetPath/views', donde 'WidgetPath' representa el directorio que contiene el fichero de clase del widget. Por lo tanto, el anterior ejemplo representará el fichero de la vista `@app/components/views/hello.php`, asumiendo que la clase del widget se encuentre en `@app/components`. Se puede sobrescribir el método [[yii\base\Widget::getViewPath()]] para personalizar el directorio que contenga los ficheros de la vista del widget.
## Mejores Practicas <a name="best-practices"></a>
## Mejores Prácticas <a name="best-practices"></a>
Los widgets son una manera orientada a objetos de reutilizar código de vistas.
Los widgets son una manera orientada a objetos de reutilizar código de las vistas.
Cuando se crean widgets, se debería continuar manteniendo el patrón MVC. En general, se debería mantener la lógica en las clases del widget y mantener la presentación en las [vistas](structure-views.md).
Los widgets deberían ser diseñados para ser autónomos. Es decir, cuando se usa un widget, se debería poder poner en una vista sin hacer nada más. Esto puede resultar complicado si un widget requiere recursos externos, tales como CSS, JavaScript, imágenes, etc. Afortunadamente Yii proporciona soporte para [paquetes asset](structure-asset-bundles.md) que pueden ser utilizados para resolver el problema.
Cuando un widget solo contiene código de vista, este es muy similar a una [vista](structure-views.md). De hecho, en este caso, su única diferencia es que un widget es una clase redistribuible, mientras que una vista es solo un script PHP llano que prefiere mantener dentro de su aplicación.
Cuando un widget sólo contiene código de vista, este es muy similar a una [vista](structure-views.md). De hecho, en este caso, su única diferencia es que un widget es una clase redistribuible, mientras que una vista es sólo un script PHP llano que prefiere mantenerse dentro de su aplicación.
Générer du code avec Gii
========================
Cette section décrit comment utiliser [Gii](tool-gii.md) pour générer du code qui implémente des fonctionnalités
courrantes de sites Web automatiquement. Utiliser Gii pour auto-générer du code consiste simplement à saisir les
bonnes informations en suivant les instructions affichées sur les pages Web Gii.
Au long de ce tutoriel, vous apprendrez comment :
* Activer Gii dans votre application
* Utiliser Gii pour générer des classes Active Record
* Utiliser Gii pour générer du code implémentant les opérations CRUD pour une table de BDD
* Personnaliser le code généré par Gii
Démarrer Gii <a name="starting-gii"></a>
------------
[Gii](tool-gii.md) est fourni dans Yii en tant que [module](structure-modules.md). Vous pouvez activer Gii en le
configurant dans la propriété [[yii\base\Application::modules|modules]] de l’application. En fonction de la manière
dont vous avez créé votre application, vous trouverez peut être que le code suivant est déjà fourni dans le fichier de
configuration `config/web.php`:
```php
$config = [ ... ];
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
```
La configuration ci-dessus établit que dans un [environnement de développement](concept-configurations.md#environment-constants),
l’application doit inclure un module appelé `gii`, qui est de classe [[yii\gii\Module]].
Si vous vérifiez le [script de démarrage](structure-entry-scripts.md) `web/index.php` de votre application, vous
les lignes suivantes, qui en gros, font que `YII_ENV_DEV` est vrai.
```php
defined('YII_ENV') or define('YII_ENV', 'dev');
```
Grâce à cette ligne, votre application est en mode développement, et aura déjà active Gii, suivant la configuration
ci-dessus. Vous pouvez maintenant accéder à Gii via l’URL suivante :
```
http://hostname/index.php?r=gii
```
> Note : Si vous accede à Gii depuis une machine autre que localhost, l’accès sera refuse par défaut pour des raisons
> de sécurité. Vous pouvez configurer Gii pour ajouter les adresses IP autorisées comme suit,
>
```php
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // ajustez cela suivant vos besoins
],
```
![Gii](images/start-gii.png)
Générer une Classe Active Record <a name="generating-ar"></a>
---------------------------------
Pour utiliser Gii pour générer une classe Active Record, sélectionnez le "Model Generator" (en cliquant sur le lien
dans la page index de Gii). Puis complétez le formulaire comme suit :
* Table Name: `country`
* Model Class: `Country`
![Générateur de Modèles](images/start-gii-model.png)
Ensuite, cliquez sur le bouton "Preview". Vous verrez que `models/Country.php` est listé comme fichier de classe à être créé. Vous pouvez cliquer sur le nom du fichier de classe pour pré visualiser son contenu.
Quand vous utilisez Gii, si vous aviez déjà créé le même fichier et que vous l’écraseriez, cliquez sur le bouton `diff`
à côté du nom de fichier pour voir les différences entre le code à être généré et la version existant.
![Pré Visualisation du Générateur de Modèle](images/start-gii-model-preview.png)
Quand vous écrasez un fichier existant, cochez la case située à côté de "overwrite" et ensuite, cliquez sur le bouton
"Generate". Si vous créez un nouveau fichier, il suffit de cliquer sur "Generate".
Ensuite, vous verrez une page de confirmation indiquand que le code a été généré avec succès. Si vous aviez un fichier
existant, vous verrez également un message indiquant qu’il a été écrasé par le code nouvellement généré.
Générer du Code CRUD <a name="generating-crud"></a>
--------------------
CRUD signifie Create, Read, Update, and Delete (Créer, Lire, Mettre à Jour et Supprimer), représentant le quatre tâches
communes entreprises avec des données sur la plupart des sites Web. Pour créer les fonctionnalités CRUD en utilisant
Gii, sélectionnez le "CRUD Generator" (en cliquant sur le lien dans la page index de Gii). Pour l’exemple de "country",
remplissez le formulaire résultant comme suit :
* Model Class: `app\models\Country`
* Search Model Class: `app\models\CountrySearch`
* Controller Class: `app\controllers\CountryController`
![CRUD Generator](images/start-gii-crud.png)
Ensuite, cliquez sur le bouton "Preview". Vous verrez une liste de fichiers à générer, comme ci-dessous.
![CRUD Generator Preview](images/start-gii-crud-preview.png)
Si vous aviez précédemment créé les fichiers `controllers/CountryController.php` et
`views/country/index.php` (dans la section bases de données du guide), cochez la case "overwrite" pour les remplacer.
(Les versions précédentes n’avaient pas de fonctionnalités CRUD).
Essayer <a name="trying-it-out"></a>
-------------
Pour voir comment ça fonctionne, utilisez votre navigateur pour accéder à l’URL suivant :
```
http://hostname/index.php?r=country/index
```
Vous verrez une grille de données montrant les pays de la table de la base de données. Vous pouvez trier la table, ou
lui appliquer des filtres en entrant des conditions de filtrage dans les entêtes de colonnes.
Pour chaque pays affiché dans la grille, vous pouvez choisir de visualiser les détails, le mettre à jour ou le
supprimer.
Vous pouvez aussi cliquer sur le bouton "Create Country" en haut de la grille pour que Yii vous fournisse un formulaire
permettant de créer un nouveau pays.
![Grille de Données Pays](images/start-gii-country-grid.png)
![Mettre à Jour un Pays](images/start-gii-country-update.png)
Ce qui suit est la liste des fichiers générés par Gii, au cas où vous souhaiteriez investiguer la manière dont ces
fonctionnalités sont implémentées, ou les personnaliser :
* Contrôleur: `controllers/CountryController.php`
* Modèles: `models/Country.php` et `models/CountrySearch.php`
* Vues: `views/country/*.php`
> Info: Gii est conçu pour être un outil de génération de code hautement personnalisable et extensible. L’utiliser avec
sagesse peut grandement accélérer le développement de vos applications. Pour plus de détails, merci de vous référer
à la section [Gii](tool-gii.md).
Résumé <a name="summary"></a>
-------
Dans cette section, vous avez appris à utiliser Gii pour générer le code qui implémente une fonctionnalité CRUD
complète pour les contenus stockés dans une table de base de données.
Hello World
============
Cette section decrit la méthode pour créer une nouvelle page "Hello" dans votre application.
Pour ce faire, vous allez créer une [action](structure-controllers.md#creating-actions) et une [vue](structure-views.md):
* L'application distribuera la requête à l'action
* et à son tour, l'action générera un rendu de la vue qui affiche le mot "Hello" à l'utilisateur.
A travers ce tutoriel, vous apprendrez trois choses :
1. Comment créer une [action](structure-controllers.md) pour répondre aux requêtes,
2. comment créer une [vue](structure-views.md) pour composer le contenu de la réponse, et
3. comment une application distribue les requêtes aux [actions](structure-controllers.md#creating-actions).
Créer une Action <a name="creating-action"></a>
------------------
Pour la tâche "Hello", vous allez créer une [action](structure-controllers.md#creating-actions) `dire` qui reçoit un paramètre
`message` de la requête et affiche ce message à l'utilisateur. Si la requête ne fournit pas de paramètre `message`, l'action affichera le message par défaut "Hello".
> Info: Les [actions](structure-controllers.md#creating-actions) sont les objets auxquels les utilisateurs peuvent directement se référer pour les exécuter. Les actions sont groupées par [contrôleurs](structure-controllers.md). Le résultat de l'exécution d'une action est la réponse que l'utilisateur recevra.
Les actions doivent être déclarées dans des [contrôleurs](structure-controllers.md). Par simplicité, vous pouvez déclarer l'action `dire` dans le contrôleur existant `SiteController`. Ce contrôleur est défini dans le fichier classe `controllers/SiteController.php`. Voici le début de la nouvelle action :
```php
<?php
namespace app\controllers;
use yii\web\Controller;
class SiteController extends Controller
{
// ...code existant...
public function actionDire($message = 'Hello')
{
return $this->render('dire', ['message' => $message]);
}
}
```
Dans le code ci-dessous, l'action `dire` est définie par une méthode nommée `actionDire` dans la classe `SiteController`.
Yii utilise le préfixe `action` pour faire la différence entre des méthodes actions et des méthodes non-actions dans une classe contrôleur.
Le nom suivant le préfixe `action` est associé à l'ID de l'action.
Quand vous choisissez le nom de vos actions, gardez à l'esprit comment Yii traite les IDs d'action. Les références aux IDs d'actions sont toujours effectuées en minuscules. Si un ID d'action nécessite plusieurs mots, ils seront concaténés à l'aide de tirets (par exemple `creer-commentaire`). Les noms de méthodes actions sont associés aux IDs d'actions en retirant tout tiret des IDs, en mettant la première lettre de chaque mot en majuscule, et en ajoutant un préfixe `action` au résultat. Par exemple,
l'ID d'action `creer-commentaire` correspond à l'action nommée `actionCreerCommentaire`.
La méthode action de notre exemple prend un paramètre `$message`, dont la valeur par défaut est `"Hello"` (de la même manière qu'on affecte une valeur par défaut à n'importe quel argument de fonction ou méthode en PHP). Quand l'application reçoit une requête et détermine que l'action `dire` est responsable de gérer ladite requête, l'application peuplera ce paramètre avec le paramètre du même nom trouvé dans la requête. En d'autres termes, si la requête contient un paramètre `message` ayant pour valeur `"Goodbye"`, la variable `$message` au sein de l'action recevra cette valeur.
Au sein de la méthode action, [[yii\web\Controller::render()|render()]] est appelé pour effectuer le rendu d'un fichier [vue](structure-views.md) appelé `dire`. Le paramètre `message` est également transmis à la vue afin qu'il puisse y être utilisé. Le résultat du rendu est renvoyé à l'utilisateur par la méthode action. Ce résultat sera reçu par l'application et présenté à l'utilisateur dans le navigateur (en tant qu'élément d'une page HTML complète).
Créer une Vue <a name="creating-view"></a>
---------------
Les [vues](structure-views.md) sont des scripts qu'on écrit pour générer le contenu d'une réponse.
Pour la tâche "Hello", vous allez créer une vue `dire` qui affiche le paramètre `message` reçu de la méthode action, et passé par l'action à la vue :
```php
<?php
use yii\helpers\Html;
?>
<?= Html::encode($message) ?>
```
La vue `dire` doit être enregistrée dans le fichier `views/site/dire.php`. Quand la méthode [[yii\web\Controller::render()|render()]]
est appelée dans une action, elle cherchera un fichier PHP nommé `views/ControllerID/NomDeLaVue.php`.
Notez que dans le code ci-dessus, le paramètre `message` est [[yii\helpers\Html::encode()|Encodé-HTML]]
avant d'être affiché. Cela est nécessaire car le paramètre vient de l'utilisateur, le rendant vulnérable aux [attaques cross-site scripting (XSS)](http://fr.wikipedia.org/wiki/Cross-site_scripting) en intégrant du code Javascript malicieux dans le paramètre.
Bien entendu, vous pouvez insérer plus de contenu dans la vue `dire`. Le contenu peut être des tags HTMML, du texte brut, ou même des expressions PHP.
En réalité, la vue `dire` est simplement un script PHP exécuté par la méthode [[yii\web\Controller::render()|render()]].
Le contenu affiché par le script de vue sera renvoyé à l'application en tant que résultat de réponse. L'application renverra à son tour ce résultat à l'utilisateur.
Essayer <a name="trying-it-out"></a>
-------------
Après avoir créé l'action et la vue, vous pouvez accéder à la nouvelle page en accédant à l'URL suivant :
```
http://hostname/index.php?r=site/dire&message=Hello+World
```
![Hello World](images/start-hello-world.png)
Le résultat de cet URL sera une page affichant "Hello World". La page a les mêmes entête et pied de page que les autres pages de l'application.
Si vous omettez le paramètre `message` dans l'URL, La page devrait simplement afficher "Hello". C'est parce que `message` est passé en paramètre de la méthode `actionDire()`, et quand il est omis, la valeur par défaut `"Hello"` sera employée à la place.
> Info: L nouvelle page a les mêmes entête et pied de page que les autres pages parce que la méthode [[yii\web\Controller::render()|render()]] intègrera automatiquement le résultat de la vue `dire` dans une pseudo [mise en page](structure-views.md#layouts) qui dans notre cas est située dans `views/layouts/main.php`.
Le paramètre `r` dans l'URL ci-dessus nécessite plus d'explications. Il signifie [route](runtime-routing.md), un ID unique commun toute l'application qui fait référence à une action. Le format de la route est `IDContrôleur/IDAction`. Quand l'application reçoit une requête, elle vérifie ce paramêtre, en utilisant la partie `IDContrôleur` pour déterminer quel classe contrôleur doit être instanciée pour traiter la requête. Ensuite, le contrôleur utilisera la partie `IDAction` pour déterminer quelle action doit être instanciée pour effectuer le vrait travail. Dans ce cas d'exemple, la route `site/dire`
sera comprise comme la classe contrôleur `SiteController` et l'action `dire`. Il en resultera que la méthode `SiteController::actionDire()` sera appelée pour traiter la requête.
> Info: De même que les actions, les contrôleurs ont des IDs qui les identifient de manière unique dans une application.
Les IDs de contrôleurs emploie les mêmes règles de nommage que les IDs d'actions. Les noms de classes Contrôleurs dérivent
des IDs de contrôleurs en retirant les tirets des IDs, en mettant la première lettre de chaque mot en majuscule,
et en suffixant la chaîne résultante du mot `Controller`. Par exemple, l'ID de contrôlleur `poster-commentaire` correspond
au nom de classe contrôleur `PosterCommentaireController`.
Résumé <a name="summary"></a>
-------
Dans cette section, vous avez touché aux parties contrôleur et vue du patron de conception MVC.
Vous avez créé une action au sein d'un contrôleur pour traiter une requête spécifique. Vous avez également créé une vue pour composer le contenu de la réponse. Dans ce simple exemple, aucun modèle n'a été impliqué car les seules données utilisées étaient le paramètre `message`.
Vous avez également appris ce que sont les routes dans Yii, qu'elles font office de pont entre les requêtes utilisateur et les actions des contrôleurs.
Dans la prochaine section, vous apprendrez comment créer un modèle, et ajouter une nouvelle page contenant un formulaire HTML.
Fonctionnement des applications
===============================
Après avoir installé Yii, vous obtenez une application Yii fonctionnelle accessible via l'URL `http://hostname/basic/web/index.php` ou `http://hostname/index.php`, en fonction
de votre configuration. Cette section vous initiera aux fonctionalités intégrées à l'application,
à la manière dont le code est organisé, et à la gestion des requêtes par l'application.
> Info: Par simplicité, au long de ce tutoriel de démarrage, nous supposerons que `basic/web` est la racine de votre
serveur Web, et que vous avez configuré l'URL pour accéder à votre application comme suit ou similaire :
`http://hostname/index.php`.
Pour vos besoins, merci d'ajuster les URLs dans notre description comme il convient.
Fonctionalité <a name="Functionality"></a>
-------------
L'application basique installée contient quatre pages :
* La page d'accueil, affichée quand vous accédez à l'URL `http://hostname/index.php`,
* la page "About" (A Propos),
* la page "Contact", qui présente un formulaire de contact permettant aux utilisateurs finaux de vous contacter par email,
* et la page "Login" (Connexion), qui presente un formulaire de connexion qui peut être utilisé pour authentifier des utilisateurs finaux. Essayez de vous connecter
avec "admin/admin", et vous verrez l'élément "Login" du menu principal être remplacé par "Logout" (Déconnexion).
Ces pages ont en commun une entête et un pied de page. L'entête contient une barre de menu principal qui permet la navigation
entre les différentes pages.
Vous devriez également voir une barre d'outils en bas de votre fenêtre de navigation.
C'est un [outil de déboggage](tool-debugger.md) utile fourni par Yii pour enregistrer et afficher de nombreuses informations de déboggage, telles que des messages de logs, statuts de réponses, les requêtes lancées vers la base de données, et ainsi de suite.
Structure de l'Application <a name="application-structure"></a>
---------------------
Les répertoires et fichiers les plus importants de votre application sont (en supposant que le répertoire racine de l'application est `basic`) :
```
basic/ chemin de base de l'application
composer.json utilisé par Composer, décrit les information de paquets
config/ contient les configurations de l'application et autres
console.php configuration de l'application console
web.php configuration de l'application Web
commands/ contient les classes de commandes console
controllers/ contient les classes de controlleurs
models/ contient les classes de modèles
runtime/ contient les fichiers générés par Yii au cours de l'exécution, tels que les fichiers de logs ou de cache and cache
vendor/ contient les paquets Composer installés, y compris le framework Yii
views/ contient les fichiers de vues
web/ racine Web de l'application, contient les fichiers accessibles via le Web
assets/ contient les fichiers assets (javascript et css) publiés par Yii
index.php le script de démarrage (ou bootstrap) pour l'application
yii le script d'exécution de Yii en commande console
```
Dans l'ensemble, les fichiers de l'application peuvent être séparés en deux types : ceux situés dans `basic/web` et ceux situés dans d'autres répertoires. Les premiers peuvent être atteints directement en HTTP (c'est à dire dans un navigateur), tandis que les seconds doivent pas l'être.
Yii est implémenté selon le patron de conception [modèle-vue-contrôleur (MVC)](http://fr.wikipedia.org/wiki/Mod%C3%A8le-vue-contr%C3%B4leur),
ce qui se reflète dans l'organisation des répertoires ci-dessus. Le répertoire `models` contient toutes les [classes modèles](structure-models.md),
le répertoire `views` contient tous les [scripts de vue](structure-views.md), et le répertoire `controllers` contient toutes les [classes contrôleurs](structure-controllers.md).
Le schéma suivant présente la structure statique d'une application.
![Structure Statique d'Application](images/application-structure.png)
Chaque application a un script de démarrage `web/index.php` qui est le seul script PHP de l'application accessible depuis le Web.
Le script de démarrage reçoit une requête et créé une instance d'[application](structure-applications.md) pour la traiter.
L'[application](structure-applications.md) résoud la requête avec l'aide de ses [composants](concept-components.md),
et distribue la requête aux éléments MVC. Les [Widgets](structure-widgets.md) sont utilisés dans les [vues](structure-views.md)
pour aider à créer des éléments d'interface complexes et dynamiques.
Cycle de vie d'une requête <a name="request-lifecycle"></a>
-----------------
Le diagramme suivant présente la manière dont une application traite une requête.
![Cycle de Vie d'une Requête](images/application-lifecycle.png)
1. Un utilisateur fait une requête au [script de démarrage](structure-entry-scripts.md) `web/index.php`.
2. Le script de démarrage charge la [configuration](concept-configurations.md) de l'application et créé une instance d'[application](structure-applications.md) pour traiter la requête.
3. L'application resoud la [route](runtime-routing.md) requise avec l'aide du composant d'application [requête](runtime-requests.md).
4. L'application créé une instance de [contrôleur](structure-controllers.md) pour traiter la requête.
5. Le contrôleur créé une instance d'[action](structure-controllers.md) et effectue les filtres pour l'action.
6. Si un filtre échoue, l'action est annuléee.
7. Si tous les filtres sont validés, l'action est exécutée.
8. L'action charge un modèle de donées, potentiellement depuis une base de données.
9. L'action génère une vue, lui fournissant le modèle de données.
10. Le résultat généré est renvoyé au composant d'application [réponse](runtime-responses.md).
11. Le composant réponse envoie le résultat généré au navigateur de l'utilisateur.
Предзагрузка
============
Предзагрузка это процесс настройки рабочей среды до того, как будет запущено приложение и обработан входящий запрос.
Предзагрузка осуществляется в двух местах: [во входном скрипте](structure-entry-scripts.md) и в [приложении](structure-applications.md).
Во [входном скрипте](structure-entry-scripts.md), регистрируются автозагрузчики классов различных библиотек. Этот процесс
включает в себя автозагрузчик классов Composer через `autoload.php` файл и автозагрузчик классов Yii через его `Yii` файл.
Затем входной скрипт загружает [конфигурацию](concept-configurations.md) приложения и создает объект [приложения](structure-applications.md).
В конструкторе приложения происходит следующий процесс предзагрузки:
1. Вызывается метод [[yii\base\Application::preInit()|preInit()]], которые конфигурирует свойства приложения, имеющие
наивысший приоритет, такие как [[yii\base\Application::basePath|basePath]];
2. Регистрируется [[yii\base\Application::errorHandler|обработчик ошибок]];
3. Происходит инициализация свойств приложения согласно заданной конфигурации;
4. Вызывается метод [[yii\base\Application::init()|init()]], который в свою очередь вызывает метод [[yii\base\Application::bootstrap()|bootstrap()]] для
запуска компонентов предзагрузки.
- Подключается файл манифеста `vendor/yiisoft/extensions.php`;
- Создаются и запускаются [компоненты предзагрузки](structure-extensions.md#bootstrapping-classes) объявленные в расширениях;
- Создаются и запускаются [компоненты приложения](structure-application-components.md) и/или [модули](structure-modules.md), объявленные
в свойстве [предзагрузка](structure-applications.md#bootstrap) приложения.
Поскольку предзагрузка осуществляется прежде чем будет обработан *каждый* запрос, то очень важно, чтобы этот процесс был легким и максимально оптимизированным.
Старайтесь не регистрировать слишком много компонентов в предзагрузке. Компонент предзагрузки нужен только тогда, когда он должен
участвовать в полном жизненном цикле процесса обработки запроса. Например, если модуль должен зарегистрировать дополнительные правила парсинга URL,
то он должен быть указан в свойстве [предзагрузка](structure-applications.md#bootstrap), чтобы новые правила URL были учтены при обработке запроса.
В производственном режиме включите байткод кэшеры, такие как APC, для минимизации времени необходимого на подключение и парсинг php файлов.
Некоторые большие приложения могут иметь сложную [конфигурацию](concept-configurations.md), которая разделена на несколько мелких файлов.
Если это тот самый случай, возможно вам стоит кэшировать весь конфигурационный файл и загружать его прямо из кэша до создания объекта
приложения во входном скрипте.
......@@ -20,7 +20,7 @@
Composer 安装后,切换到一个可通过 Web 访问的目录,执行如下命令即可安装 Yii :
composer global require "fxp/composer-asset-plugin:1.0.0-beta1"
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
第一条命令安装 [composer asset plugin](https://github.com/francoispluchino/composer-asset-plugin/),它是通过 Composer 管理 bower 和 npm 包所必须的,此命令全局应用,只需执行一次即可。
......
......@@ -47,10 +47,11 @@ Application Structure
Handling Requests
-----------------
* **TBD** [Bootstrapping](runtime-bootstrapping.md)
* **TBD** [Routing](runtime-routing.md)
* **TBD** [Requests](runtime-requests.md)
* **TBD** [Responses](runtime-responses.md)
* [Overview](runtime-overview.md)
* [Bootstrapping](runtime-bootstrapping.md)
* [Routing](runtime-routing.md)
* [Requests](runtime-requests.md)
* [Responses](runtime-responses.md)
* **TBD** [Sessions and Cookies](runtime-sessions-cookies.md)
* [URL Parsing and Generation](runtime-url-handling.md)
* [Handling Errors](runtime-handling-errors.md)
......@@ -81,7 +82,7 @@ Working with Databases
* **TBD** [Sphinx](db-sphinx.md)
* **TBD** [Redis](db-redis.md)
* **TBD** [MongoDB](db-mongodb.md)
* **TBD** [ElasticSearch](db-elastic-search.md)
* **TBD** [ElasticSearch](db-elasticsearch.md)
Getting Data from Users
......@@ -96,7 +97,7 @@ Getting Data from Users
Displaying Data
---------------
* **TBD** [Data Formatting](output-formatting.md)
* **TBD** [Data Formatting](output-formatter.md)
* **TBD** [Pagination](output-pagination.md)
* **TBD** [Sorting](output-sorting.md)
* [Data Providers](output-data-providers.md)
......@@ -151,7 +152,7 @@ Testing
-------
* [Overview](test-overview.md)
* [Testing environment setup](test-endvironment-setup.md)
* [Testing environment setup](test-environment-setup.md)
* [Unit Tests](test-unit.md)
* [Functional Tests](test-functional.md)
* [Acceptance Tests](test-acceptance.md)
......
......@@ -177,7 +177,7 @@ function whose return value determines whether to apply the rule or not. For exa
['state', 'required', 'when' => function ($model) {
return $model->country == 'USA';
}, 'whenClient' => "function (attribute, value) {
return $('#country').value == 'USA';
return $('#country').val() == 'USA';
}"],
]
```
......
......@@ -68,7 +68,8 @@ For more details about the available properties check out the [[yii\i18n\Formatt
'decimalSeparator' => ',',
'thousandSeparator' => ' ',
'currencyCode' => 'EUR',
];
],
],
```
Formatting Dates
......@@ -88,6 +89,8 @@ See http://site.icu-project.org/ for the format.
and now in human readable form.
The input value for date and time formatting is assumed to be in UTC unless a timezone is explicitly given.
Formatting Numbers
------------------
......
......@@ -17,7 +17,7 @@ with response formatting:
Yii supports content negotiation via the [[yii\filters\ContentNegotiator]] filter. The RESTful API base
controller class [[yii\rest\Controller]] is equipped with this filter under the name of `contentNegotiator`.
The filer provides response format negotiation as well as language negotiation. For example, if a RESTful
The filter provides response format negotiation as well as language negotiation. For example, if a RESTful
API request contains the following header,
```
......
......@@ -75,4 +75,4 @@ For example, to support a new action `search` by the endpoint `GET /users/search
You may have noticed that the controller ID `user` appears in plural form as `users` in the endpoints.
This is because [[yii\rest\UrlRule]] automatically pluralizes controller IDs for them to use in endpoints.
You may disable this behavior by setting [[yii\rest\UrlRule::pluralize]] to be false, or if you want
to use some special names you may configure the [[yii\rest\UrlRule::controller]] property.
to use some special names you may configure the [[yii\rest\UrlRule::controller]] property. Note that the pluralization of RESTful endpoints does not always simply add an "s" to the end of the controller id. A controller whose ID ends in "x", for example "BoxController" (with ID `box`), has RESTful endpoints pluralized to `boxes` by [[yii\rest\UrlRule]].
......@@ -69,9 +69,11 @@ return [
'modules' => [
'v1' => [
'basePath' => '@app/modules/v1',
'controllerNamespace' => 'app\modules\v1\controllers',
],
'v2' => [
'basePath' => '@app/modules/v2',
'controllerNamespace' => 'app\modules\v2\controllers',
],
],
'components' => [
......
Bootstrapping
=============
Bootstrapping refers to the process of preparing the environment before an application starts
to resolve and process an incoming request. Bootstrapping is done in two places:
the [entry script](structure-entry-scripts.md) and the [application](structure-applications.md).
In the [entry script](structure-entry-scripts.md), class autoloaders for different libraries are
registered. This includes the Composer autoloader through its `autoload.php` file and the Yii
autoloader through its `Yii` class file. The entry script then loads the application
[configuration](concept-configurations.md) and creates an [application](structure-applications.md) instance.
In the constructor of the application, the following bootstrapping work are done:
1. [[yii\base\Application::preInit()|preInit()]] is called, which configures some high priority
application properties, such as [[yii\base\Application::basePath|basePath]].
2. Register the [[yii\base\Application::errorHandler|error handler]].
3. Initialize application properties using the given application configuration.
4. [[yii\base\Application::init()|init()]] is called which in turn calls
[[yii\base\Application::bootstrap()|bootstrap()]] to run bootstrapping components.
- Include the extension manifest file `vendor/yiisoft/extensions.php`.
- Create and run [bootstrap components](structure-extensions.md#bootstrapping-classes)
declared by extensions.
- Create and run [application components](structure-application-components.md) and/or
[modules](structure-modules.md) that are declared in the application's
[bootstrap property](structure-applications.md#bootstrap).
Because the bootstrapping work has to be done before handling *every* request, it is very important
to keep this process light and optimize it as much as possible.
Try not to register too many bootstrapping components. A bootstrapping component is needed only
if it wants to participate the whole life cycle of requesting handling. For example, if a module
needs to register additional URL parsing rules, it should be listed in the
[bootstrap property](structure-applications.md#bootstrap) so that the new URL rules can take effect
before they are used to resolve requests.
In production mode, enable bytecode cache, such as APC, to minimize the time needed for including
and parsing PHP files.
Some large applications have very complex application [configurations](concept-configurations.md)
which are divided into many smaller configuration files. If this is the case, consider caching
the whole configuration array and loading it directly from cache before creating the application instance
in the entry script.
Overview
========
Each time when a Yii application handles a request, it undergoes a similar workflow.
1. A user makes a request to the [entry script](structure-entry-scripts.md) `web/index.php`.
2. The entry script loads the application [configuration](concept-configurations.md) and creates
an [application](structure-applications.md) instance to handle the request.
3. The application resolves the requested [route](runtime-routing.md) with the help of
the [request](runtime-requests.md) application component.
4. The application creates a [controller](structure-controllers.md) instance to handle the request.
5. The controller creates an [action](structure-controllers.md) instance and performs the filters for the action.
6. If any filter fails, the action is cancelled.
7. If all filters pass, the action is executed.
8. The action loads a data model, possibly from a database.
9. The action renders a view, providing it with the data model.
10. The rendered result is returned to the [response](runtime-responses.md) application component.
11. The response component sends the rendered result to the user's browser.
The following diagram shows how an application handles a request.
![Request Lifecycle](images/application-lifecycle.png)
In this section, we will describe in detail how some of these steps work.
Requests
========
Requests made to an application are represented in terms of [[yii\web\Request]] objects which provide information
such as request parameters, HTTP headers, cookies, etc. For a given request, you can get access to the corresponding
request object via the `request` [application component](structure-application-components.md). In this section,
we will describe how you can make use of this component in your applications.
## Request Parameters <a name="request-parameters"></a>
To get request parameters, you can call [[yii\web\Request::get()|get()]] and [[yii\web\Request::post()|post()]] methods
of the `request` component. They return the values of `$_GET` and `$_POST`, respectively. For example,
```php
$request = Yii::$app->request;
$get = $request->get();
// equivalent to: $get = $_GET;
$id = $request->get('id');
// equivalent to: $id = isset($_GET['id']) ? $_GET['id'] : null;
$id = $request->get('id', 1);
// equivalent to: $id = isset($_GET['id']) ? $_GET['id'] : 1;
$post = $request->post();
// equivalent to: $post = $_POST;
$name = $request->post('name');
// equivalent to: $name = isset($_POST['name']) ? $_POST['name'] : null;
$name = $request->post('name', '');
// equivalent to: $name = isset($_POST['name']) ? $_POST['name'] : '';
```
> Info: Instead of directly accessing `$_GET` and `$_POST` to retrieve the request parameters, it is recommended
that you get them via the `request` component like shown above. This will make writing tests easier because
you can create a mock request component with faked request data.
When implementing [RESTful APIs](rest-quick-start.md), you often need to retrieve parameters that are submitted
via PUT, PATCH or other [request methods](#request-methods). You can get these parameters by calling
the [[yii\web\Request::getBodyParam()]] methods. For example,
```php
$request = Yii::$app->request;
// returns all parameters
$params = $request->bodyParams;
// returns the parameter "id"
$param = $request->getBodyParam('id');
```
> Info: Unlike `GET` parameters, parameters submitted via `POST`, `PUT`, `PATCH` etc. are sent in the request body.
The `request` component will parse these parameters when you access them through the methods described above.
You can customize the way how these parameters are parsed by configuring the [[yii\web\Request::parsers]] property.
## Request Methods <a name="request-methods"></a>
You can get the HTTP method used by the current request via the expression `Yii::$app->request->method`.
A whole set of boolean properties are also provided for you to check if the current method is of certain type.
For example,
```php
$request = Yii::$app->request;
if ($request->isAjax) { // the request is an AJAX request }
if ($request->isGet) { // the request method is GET }
if ($request->isPost) { // the request method is POST }
if ($request->isPut) { // the request method is PUT }
```
## Request URLs <a name="request-urls"></a>
The `request` component provides many ways of inspecting the currently requested URL.
Assuming the URL being requested is `http://example.com/admin/index.php/product?id=100`, you can get various
parts of this URL as summarized in the following:
* [[yii\web\Request::url|url]]: returns `/admin/index.php/product?id=100`, which is the URL without the host info part.
* [[yii\web\Request::absoluteUrl|absoluteUrl]]: returns `http://example.com/admin/index.php/product?id=100`,
which is the whole URL including the host info part.
* [[yii\web\Request::hostInfo|hostInfo]]: returns `http://example.com`, which is the host info part of the URL.
* [[yii\web\Request::pathInfo|pathInfo]]: returns `/product`, which is the part after the entry script and
before the question mark (query string).
* [[yii\web\Request::queryString|queryString]]: returns `id=100`, which is the part after the question mark.
* [[yii\web\Request::baseUrl|baseUrl]]: returns `/admin`, which is the part after the host info and before
the entry script name.
* [[yii\web\Request::scriptUrl|scriptUrl]]: returns `/admin/index.php`, which is the URL without path info and query string.
* [[yii\web\Request::serverName|serverName]]: returns `example.com`, which is the host name in the URL.
* [[yii\web\Request::serverPort|serverPort]]: returns 80, which is the port used by the Web server.
## HTTP Headers <a name="http-headers"></a>
You can get the HTTP header information through the [[yii\web\HeaderCollection|header collection]] returned
by the [[yii\web\Request::headers]] property. For example,
```php
// $headers is an object of yii\web\HeaderCollection
$headers = Yii::$app->request->headers;
// returns the Accept header value
$accept = $headers->get('Accept');
if ($headers->has('User-Agent')) { // there is User-Agent header }
```
The `request` component also provides support for quickly accessing some commonly used headers, including
* [[yii\web\Request::userAgent|userAgent]]: returns the value of the `User-Agent` header.
* [[yii\web\Request::contentType|contentType]]: returns the value of the `Content-Type` header which indicates
the MIME type of the data in the request body.
* [[yii\web\Request::acceptableContentTypes|acceptableContentTypes]]: returns the content MIME types acceptable by users.
The returned types ordered by the quality score. Types with the highest scores will be returned first.
* [[yii\web\Request::acceptableLanguages|acceptableLanguages]]: returns the languages acceptable by users.
The returned languages are ordered by their preference level. The first element represents the most preferred language.
If your application supports multiple languages and you want to display pages in the language that is the most preferred
by the end user, you may use the language negotiation method [[yii\web\Request::getPreferredLanguage()]].
This method takes a list of languages supported by your application, compares them with [[yii\web\Request::acceptableLanguages|acceptableLanguages]],
and returns the most appropriate language.
> Tip: You may also use the [[yii\filters\ContentNegotiator|ContentNegotiator]] filter to dynamically determine
what content type and language should be used in the response. The filter implements the content negotiation
on top the properties and methods described above.
## Client Information <a name="client-information"></a>
You can get the host name and IP address of the client machine through [[yii\web\Request::userHost|userHost]]
and [[yii\web\Request::userIP|userIP]], respectively. For example,
```php
$userHost = Yii::$app->request->userHost;
$userIP = Yii::$app->request->userIP;
```
Routing
=======
When the [[yii\web\Application::run()|run()]] method is called by the [entry script](structure-entry-scripts.md),
the first thing it does is to resolve the incoming request and instantiate an appropriate
[controller action](structure-controllers.md) to handle the request. This process is called *routing*.
## Resolving Route <a name="resolving-route"></a>
The first step of routing is to parse the incoming request into a route which, as described in
the [Controllers](structure-controllers.md#routes) section, is used to address a controller action.
This is done by [[yii\web\Request::resolve()|resolve()]] method of the `request` application component.
The method invokes the [URL manager](runtime-url-handling.md) to do the actual request parsing work.
By default, if the incoming request contains a `GET` parameter named `r`, its value will be considered
as the route. However, if the [[yii\web\UrlManager::enablePrettyUrl|pretty URL feature]] is enabled,
more work will be done to determine the requested route. For more details, please refer to
the [URL Parsing and Generation](runtime-url-handling.md) section.
In case a route cannot be determined, the `request` component will throw a [[yii\web\NotFoundHttpException]].
### Default Route <a name="default-route"></a>
If an incoming request does not specify a route, which often happens to the request for homepages,
the route specified by [[yii\web\Application::defaultRoute]] will be used. The default value of this property
is `site/index`, which refers to the `index` action of the `site` controller. You may customize this property
in the application configuration like the following:
```php
return [
// ...
'defaultRoute' => 'main/index',
];
```
### `catchAll` Route <a name="catchall-route"></a>
Sometimes, you may want to put your Web application in maintenance mode temporarily and display the same
informational page for all requests. There are many ways to accomplish this goal. But one of the simplest
ways is to configure the [[yii\web\Application::catchAll]] property like the following in the application configuration:
```php
return [
// ...
'catchAll' => ['site/offline'],
];
```
The `catchAll` property should take an array whose first element specifies a route, and
the rest of the elements (name-value pairs) specify the parameters to be bound to the action.
When the `catchAll` property is set, it will replace any route resolved from the incoming requests.
With the above configuration, the same `site/offline` action will be used to handle all incoming requests.
## Creating Action <a name="creating-action"></a>
Once the requested route is determined, the next step is to create the action object corresponding to the route.
The route is broken down into multiple parts by the slashes in it. For example, `site/index` will be
broken into `site` and `index`. Each part is an ID which may refer to a module, a controller or an action.
Starting from the first part in the route, the application conducts the following steps to create modules (if any),
the controller and the action:
1. Set the application as the current module.
2. Check if the [[yii\base\Module::controllerMap|controller map]] of the current module contains the current ID.
If so, a controller object will be created according to the controller configuration found in the map,
and do Step 5 with the rest parts of the route.
3. Check if the ID refers to a module listed in the [[yii\base\Module::modules|modules]] property of
the current module. If so, a module is created according to the configuration found in the module list,
and do Step 2 with the next part in the route under the context of the newly created module.
4. Treat the ID as a controller ID and create a controller object. Do the next step with the rest part of
the route.
5. The controller looks for the current ID in its [[yii\base\Controller::actions()|action map]]. If found,
it creates an action according to the configuration found in the map. Otherwise, the controller will
attempt to create an inline action which is defined by an action method corresponding to the current ID.
Among the above steps, if any error occurs, a [[yii\web\NotFoundHttpException]] will be thrown, indicating
failure of the routing.
......@@ -3,7 +3,7 @@ Working with Databases
This section will describe how to create a new page that displays country data fetched from
a database table named `country`. To achieve this goal, you will configure a database connection,
create an [Active Record](db-active-record.md) class, and define an [action](structure-controllers.md),
create an [Active Record](db-active-record.md) class, define an [action](structure-controllers.md),
and create a [view](structure-views.md).
Through this tutorial, you will learn how to:
......
......@@ -123,8 +123,8 @@ If the model is successfully populated (i.e., if the user has submitted the HTML
provides components such as `request`, `response`, `db`, etc. to support specific functionality.
In the above code, the `request` component of the application instance is used to access the `$_POST` data.
If everything is fine, the action will render a view named `entry-confirm` to confirm the data entered
with the user that the data entered. If no data is submitted or the data contains errors, the `entry` view will
If everything is fine, the action will render a view named `entry-confirm` to confirm the successful submission
of the data to the user. If no data is submitted or the data contains errors, the `entry` view will
be rendered, wherein the HTML form will be shown, along with any validation error messages.
> Note: In this very simple example we just render the confirmation page upon valid data submission. In practice,
......
......@@ -4,7 +4,7 @@ Installing Yii
You can install Yii in two ways, using [Composer](http://getcomposer.org/) or by downloading an archive file.
The former is the preferred way, as it allows you to install new [extensions](extend-creating-extensions.md) or update Yii by simply running a single command.
> Note: Unlike with Yii 1, standard installations of Yii 2 results in both the framework and an application skeleton being downloaded and installed.
> Note: Unlike with Yii 1, standard installations of Yii 2 result in both, the framework and an application skeleton being downloaded and installed.
Installing via Composer <a name="installing-via-composer"></a>
......@@ -21,16 +21,24 @@ On Windows, you'll download and run [Composer-Setup.exe](https://getcomposer.org
Please refer to the [Composer Documentation](https://getcomposer.org/doc/) if you encounter any
problems or want to learn more about Composer usage.
If you had Composer already installed before, make sure you use an up to date version. You can update Composer
by running `composer self-update`.
With Composer installed, you can install Yii by running the following commands under a Web-accessible folder:
composer global require "fxp/composer-asset-plugin:1.0.0-beta1"
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
The first command installs the [composer asset plugin](https://github.com/francoispluchino/composer-asset-plugin/)
which allows managing bower and npm package dependencies through composer. You only need to run this command
once for all. The second command installs Yii in a directory named `basic`.
which allows managing bower and npm package dependencies through Composer. You only need to run this command
once for all. The second command installs Yii in a directory named `basic`. You can choose a different directory name if you want.
> Note: During the installation it may happen that Composer asks for login credentials for your Github account because it hits the
> Github API rate-limit. This is normal because Composer needs to retrieve a lot of information for all the packages from Github.
> Logging in to Github increases the API rate-limit so Composer can go on with its work. For more details, please refer to the
> [Composer documentation](https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens).
> Tip: If you want to install the latest development version of Yii, you may use the following command,
> Tip: If you want to install the latest development version of Yii, you may use the following command instead,
> which adds a [stability option](https://getcomposer.org/doc/04-schema.md#minimum-stability):
>
> composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
......@@ -41,9 +49,9 @@ once for all. The second command installs Yii in a directory named `basic`.
Installing from an Archive File <a name="installing-from-archive-file"></a>
-------------------------------
Installing Yii from an archive file involves two steps:
Installing Yii from an archive file involves three steps:
1. Download the archive file from [yiiframework.com](http://www.yiiframework.com/download/yii2-basic).
1. Download the archive file from [yiiframework.com](https://github.com/yiisoft/yii2/releases/download/2.0.0-rc/yii-basic-app-2.0.0-rc.tgz).
2. Unpack the downloaded file to a Web-accessible folder.
3. Modify the `config/web.php` file by entering a secret key for the `cookieValidationKey` configuration item
(this is done automatically if you are installing Yii using Composer):
......@@ -135,8 +143,8 @@ should replace `path/to/basic/web` with the actual path for `basic/web`.
DocumentRoot "path/to/basic/web"
<Directory "path/to/basic/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
......
......@@ -25,9 +25,9 @@ This section will summarize the Yii resources available to help you be more prod
* [Extensions](http://www.yiiframework.com/extensions/):
Yii boasts a library of thousands of user-contributed extensions that can be easily plugged into your applications, thereby making your application development even faster and easier.
* Community
- [Forum](http://www.yiiframework.com/forum/)
- [GitHub](https://github.com/yiisoft/yii2)
- [Facebook](https://www.facebook.com/groups/yiitalk/)
- [Twitter](https://twitter.com/yiiframework)
- [LinkedIn](https://www.linkedin.com/groups/yii-framework-1483367)
- Forum: <http://www.yiiframework.com/forum/>
- IRC chat: The #yii channel on the freenode network (<irc://irc.freenode.net/yii>)
- GitHub: <https://github.com/yiisoft/yii2>
- Facebook: <https://www.facebook.com/groups/yiitalk/>
- Twitter: <https://twitter.com/yiiframework>
- LinkedIn: <https://www.linkedin.com/groups/yii-framework-1483367>
......@@ -240,15 +240,13 @@ be the corresponding [configuration arrays](concept-configurations.md).
> Tip: You can conditionally choose which assets to use in an asset bundle. The following example shows how
> to use `jquery.js` in the development environment and `jquery.min.js` otherwise:
>
```php
'yii\web\JqueryAsset' => [
'js' => [
YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js'
]
],
```
> ```php
> 'yii\web\JqueryAsset' => [
> 'js' => [
> YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js'
> ]
> ],
> ```
You can disable one or multiple asset bundles by associating `false` with the names of the asset bundles
that you want to disable. When you register a disabled asset bundle with a view, none of its dependent bundles
......
......@@ -17,7 +17,7 @@ To use an extension, you need to install it first. Most extensions are distribut
packages which can be installed by taking the following two simple steps:
1. modify the `composer.json` file of your application and specify which extensions (Composer packages) you want to install.
2. run `php composer.phar install` to install the specified extensions.
2. run `composer install` to install the specified extensions.
Note that you may need to install [Composer](https://getcomposer.org/) if you do not have it.
......@@ -172,7 +172,7 @@ We recommend you prefix `yii2-` to the project name for packages representing Yi
It is important that you specify the package type of your extension as `yii2-extension` so that the package can
be recognized as a Yii extension when being installed.
When a user runs `php composer.phar install` to install an extension, the file `vendor/yiisoft/extensions.php`
When a user runs `composer install` to install an extension, the file `vendor/yiisoft/extensions.php`
will be automatically updated to include the information about the new extension. From this file, Yii applications
can know which extensions are installed (the information can be accessed via [[yii\base\Application::extensions]].
......
......@@ -19,7 +19,7 @@ Gii is an official Yii extension. The preferred way to install this extension is
You can either run this command:
```
php composer.phar require --prefer-dist yiisoft/yii2-gii "*"
composer require "yiisoft/yii2-gii:*"
```
Or you can add this code to the require section of your `composer.json` file:
......
......@@ -12,19 +12,18 @@ 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:
If you do not have [Composer](http://getcomposer.org/), follow the instructions in the
[Installing Yii](start-installation.md#installing-via-composer) section to install it.
~~~
curl -sS http://getcomposer.org/installer | php
~~~
With Composer installed, you can then install the application using the following commands:
You can then install the application using the following command:
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced yii-application
~~~
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta1"
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced /path/to/yii-application
~~~
The first command installs the [composer asset plugin](https://github.com/francoispluchino/composer-asset-plugin/)
which allows managing bower and npm package dependencies through Composer. You only need to run this command
once for all. The second command installs the advanced application in a directory named `yii-application`.
You can choose a different directory name if you want.
Getting started
---------------
......@@ -87,6 +86,8 @@ Predefined path aliases
- `@console` - console directory.
- `@runtime` - runtime directory of currently running web application.
- `@vendor` - Composer vendor directory.
- `@bower` - vendor directory that contains the [bower packages](http://bower.io/).
- `@npm` - vendor directory that contains [npm packages](https://www.npmjs.org/).
- `@web` - base URL of currently running web application.
- `@webroot` - web root directory of currently running web application.
......@@ -202,7 +203,7 @@ your project.
Now the interesting part. You can add more packages your application needs to the `require` section.
All these packages are coming from [packagist.org](https://packagist.org/) so feel free to browse the website for useful code.
After your `composer.json` is changed you can run `php composer.phar update --prefer-dist`, wait till packages are downloaded and
After your `composer.json` is changed you can run `composer update --prefer-dist`, wait till packages are downloaded and
installed and then just use them. Autoloading of classes will be handled automatically.
Creating links from backend to frontend
......
......@@ -7,8 +7,8 @@ Internationalization (I18N) refers to the process of designing a software applic
various languages and regions without engineering changes. For Web applications, this is of particular importance
because the potential users may be worldwide.
Yii offers several tools that help with internationalisation of a website such as [message translation][],
[number and date formatting][].
Yii offers several tools that help with internationalisation of a website such as message translation and
number- and date-formatting.
Locale and Language
-------------------
......
......@@ -48,6 +48,6 @@ Use the Template
That's all that's required to create a new Yii application template. Now you can create projects using your template:
```
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta1"
php composer.phar create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project
```
......@@ -112,7 +112,7 @@ There are two ways of referencing templates in `include` and `extends` statement
```
{% include "comment.twig" %}
{% extends "post.twig" %
{% extends "post.twig" %}
{% include "@app/views/snippets/avatar.twig" %}
{% extends "@app/views/layouts/2columns.twig" %}
......
......@@ -17,7 +17,7 @@ Many third-party libraries are released in terms of [Composer](https://getcompos
You can install such libraries by taking the following two simple steps:
1. modify the `composer.json` file of your application and specify which Composer packages you want to install.
2. run `php composer.phar install` to install the specified packages.
2. run `composer install` to install the specified packages.
The classes in the installed Composer packages can be autoloaded using the Composer autoloader. Make sure
the [entry script](structure-entry-scripts.md) of your application contains the following lines to install
......@@ -83,8 +83,8 @@ If the third-party system uses Composer to manage its dependencies, you can simp
to install Yii:
```
php composer.phar require yiisoft/yii2-framework:*
php composer.phar install
composer require "yiisoft/yii2:*"
composer install
```
Otherwise, you can [download](http://www.yiiframework.com/download/) the Yii release file and unpack it in
......@@ -101,7 +101,8 @@ new yii\web\Application($yiiConfig); // Do NOT call run() here
As you can see, the code above is very similar to that in the [entry script](structure-entry-scripts.md) of
a typical Yii application. The only difference is that after the application instance is created, the `run()` method
is not called. This is because by calling `run()`, Yii will take over the control of the request handling workflow.
is not called. This is because by calling `run()`, Yii will take over the control of the request handling workflow
which is not needed in this case and already handled by the existing application.
Like in a Yii application, you should configure the application instance based on the environment running
the third-party system. For example, to use the [Active Record](db-active-record.md) feature, you need to configure
......@@ -118,9 +119,9 @@ the whole application in Yii 2, you may just want to enhance it using some of th
This can be achieved as described below.
> Note: Yii 2 requires PHP 5.4 or above. You should make sure that both your server and the existing application
support this.
> support this.
First, install Yii 2 in your existing application by following the instructions given in the last subsection.
First, install Yii 2 in your existing application by following the instructions given in the [last subsection](#using-yii-in-others).
Second, modify the entry script of the application as follows,
......@@ -149,13 +150,14 @@ require($yii1path . '/YiiBase.php'); // Yii 1.x
class Yii extends \yii\BaseYii
{
// copy-paste the code in YiiBase (1.x) here
// copy-paste the code from YiiBase (1.x) here
}
Yii::$classMap = include($yii2path . '/classes.php');
// register Yii2 autoloader via Yii1
Yii::registerAutoloader(['Yii', 'autoload']);
// create the dependency injection container
Yii::$container = new yii\di\Container;
```
That's all! Now in any part of your code, you can use `Yii::$app` to access the Yii 2 application instance, while
......
......@@ -24,7 +24,6 @@ convenient way to include bootstrap assets in your pages with a single line adde
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset', // this line
// 'yii\bootstrap\BootstrapThemeAsset' // uncomment to apply bootstrap 2 style to bootstrap 3
];
```
......
......@@ -23,12 +23,13 @@ structure-models.md | Yes
structure-modules.md | Yes
structure-filters.md | Yes
structure-widgets.md | Yes
structure-assets.md |
structure-assets.md | Yes
structure-extensions.md | Yes
runtime-bootstrapping.md |
runtime-routing.md |
runtime-requests.md |
runtime-responses.md |
runtime-overview.md | Yes
runtime-bootstrapping.md | Yes
runtime-routing.md | Yes
runtime-requests.md | Yes
runtime-responses.md | Yes
runtime-sessions-cookies.md |
runtime-url-handling.md |
runtime-handling-errors.md |
......
Yii Framework 2 apidoc extension Change Log
===========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- no changes in this release.
......
......@@ -41,6 +41,7 @@ class ApiMarkdownLaTeX extends GithubMarkdown
{
list($html, $offset) = $this->parseApiLinks($text);
// TODO allow break also on camel case
$latex = '\texttt{'.str_replace(['\\textbackslash', '::'], ['\allowbreak{}\\textbackslash', '\allowbreak{}::\allowbreak{}'], $this->escapeLatex(strip_tags($html))).'}';
return [$latex, $offset];
......
......@@ -36,6 +36,7 @@ trait ApiMarkdownTrait
// Collection resolves relative types
$typeName = (new Collection([$typeName], $context->phpDocContext))->__toString();
}
/** @var $type TypeDoc */
$type = static::$renderer->apiContext->getType($typeName);
if ($type === null) {
static::$renderer->apiContext->errors[] = [
......
......@@ -37,6 +37,21 @@ class TypeDoc extends BaseDoc
public $namespace;
/**
* Finds subject (method or property) by name
*
* If there is a property with the same as a method, the method will be returned if the name is not stated
* explicitly by prefixing with `$`.
*
* Example for method `attributes()` and property `$attributes` which both may exist:
*
* - `$subjectName = '$attributes'` finds a property or nothing.
* - `$subjectName = 'attributes()'` finds a method or nothing.
* - `$subjectName = 'attributes'` finds the method if it exists, if not it will find the property.
*
* @param $subjectName
* @return null|MethodDoc|PropertyDoc
*/
public function findSubject($subjectName)
{
if ($subjectName[0] != '$') {
......
Yii Framework 2 authclient extension Change Log
===============================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #3633: OpenId return URL comparison advanced to prevent url encode problem (klimov-paul)
- Bug #4490: `yii\authclient\widgets\AuthChoice` does not preserve initial settings while opening popup (klimov-paul)
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* Asset bundle for the Twitter bootstrap default theme.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class BootstrapThemeAsset extends AssetBundle
{
public $sourcePath = '@bower/bootstrap/dist';
public $css = [
'css/bootstrap-theme.css',
];
public $depends = [
'yii\bootstrap\BootstrapAsset',
];
}
Yii Framework 2 bootstrap extension Change Log
==============================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- Chg #5231: Collapse `items` property uses `label` element instead of array key for headers (nkovacs)
- Chg #5232: Collapse encodes headers by default (nkovacs)
- Chg #5217: Tabs no longer requires content since empty tab could be used dynamically (damiandennis)
2.0.0-rc September 27, 2014
---------------------------
- Bug #3292: Fixed dropdown widgets rendering incorrect HTML (it3rmit)
- Bug #3740: Fixed duplicate error message when client validation is enabled (tadaszelvys)
......
......@@ -20,13 +20,15 @@ use yii\helpers\Html;
* echo Collapse::widget([
* 'items' => [
* // equivalent to the above
* 'Collapsible Group Item #1' => [
* [
* 'label' => 'Collapsible Group Item #1',
* 'content' => 'Anim pariatur cliche...',
* // open its content by default
* 'contentOptions' => ['class' => 'in']
* ],
* // another group item
* 'Collapsible Group Item #2' => [
* [
* 'label' => 'Collapsible Group Item #1',
* 'content' => 'Anim pariatur cliche...',
* 'contentOptions' => [...],
* 'options' => [...],
......@@ -45,20 +47,22 @@ class Collapse extends Widget
* @var array list of groups in the collapse widget. Each array element represents a single
* group with the following structure:
*
* ```php
* // item key is the actual group header
* 'Collapsible Group Item #1' => [
* // required, the content (HTML) of the group
* 'content' => 'Anim pariatur cliche...',
* // optional the HTML attributes of the content group
* 'contentOptions' => [],
* // optional the HTML attributes of the group
* 'options' => [],
* ]
* - label: string, required, the group header label.
* - encode: boolean, optional, whether this label should be HTML-encoded. This param will override
* global `$this->encodeLabels` param.
* - content: string, required, the content (HTML) of the group
* - options: array, optional, the HTML attributes of the group
* - contentOptions: optional, the HTML attributes of the group's content
*
* ```
*/
public $items = [];
/**
* @var boolean whether the labels for header items should be HTML-encoded.
*/
public $encodeLabels = true;
/**
* Initializes the widget.
......@@ -88,7 +92,11 @@ class Collapse extends Widget
{
$items = [];
$index = 0;
foreach ($this->items as $header => $item) {
foreach ($this->items as $item) {
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$header = $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
Html::addCssClass($options, 'panel panel-default');
$items[] = Html::tag('div', $this->renderItem($header, $item, ++$index), $options);
......@@ -113,6 +121,11 @@ class Collapse extends Widget
$options['id'] = $id;
Html::addCssClass($options, 'panel-collapse collapse');
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
if ($encodeLabel) {
$header = Html::encode($header);
}
$headerToggle = Html::a($header, '#' . $id, [
'class' => 'collapse-toggle',
'data-toggle' => 'collapse',
......
......@@ -62,10 +62,10 @@ class Tabs extends Widget
* global `$this->encodeLabels` param.
* - headerOptions: array, optional, the HTML attributes of the tab header.
* - linkOptions: array, optional, the HTML attributes of the tab header link tags.
* - content: string, required if `items` is not set. The content (HTML) of the tab pane.
* - content: string, optional, the content (HTML) of the tab pane.
* - options: array, optional, the HTML attributes of the tab pane container.
* - active: boolean, optional, whether the item tab header and pane should be visible or not.
* - items: array, optional, if not set then `content` will be required. The `items` specify a dropdown items
* - items: array, optional, can be used instead of `content` to specify a dropdown items
* configuration array. Each item can hold three extra keys, besides the above ones:
* * active: boolean, optional, whether the item tab header and pane should be visible or not.
* * content: string, required if `items` is not set. The content (HTML) of the tab pane.
......@@ -168,8 +168,6 @@ class Tabs extends Widget
$linkOptions['data-toggle'] = 'tab';
$header = Html::a($label, '#' . $options['id'], $linkOptions);
$panes[] = Html::tag('div', $item['content'], $options);
} else {
throw new InvalidConfigException("Either the 'content' or 'items' option must be set.");
}
$headers[] = Html::tag('li', $header, $headerOptions);
......
......@@ -19,7 +19,7 @@
],
"require": {
"yiisoft/yii2": "*",
"bower-asset/bootstrap": "3.2.* | ~3.1"
"bower-asset/bootstrap": "3.2.* | 3.1.*"
},
"autoload": {
"psr-4": {
......
Yii Framework 2 Codeception extension Change Log
================================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- no changes in this release.
......
Yii Framework 2 composer extension Change Log
=============================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #3438: Fixed support for non-lowercase package names (cebe)
- Chg: Added `yii\composer\Installer::postCreateProject()` and modified the syntax of calling installer methods in composer.json (qiangxue)
......
Yii Framework 2 debug extension Change Log
==========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #1263: Fixed the issue that Gii and Debug modules might be affected by incompatible asset manager configuration (qiangxue)
- Bug #3956: Debug toolbar was affecting flash message removal (samdark)
......
Yii Framework 2 elasticsearch extension Change Log
==================================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #3587: Fixed an issue with storing empty records (cebe)
- Bug #4187: Elasticsearch dynamic scripting is disabled in 1.2.0, so do not use it in query builder (cebe)
......
Yii Framework 2 faker extension Change Log
==============================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Chg #4622: Simplified the way of creating a Faker fixture template file (qiangxue)
......
......@@ -101,20 +101,20 @@ use yii\helpers\VarDumper;
* //list all templates under specified template path
* yii fixture/templates --templatePath='@app/path/to/my/custom/templates'
* ~~~
*
*
* You also can create your own data providers for custom tables fields, see Faker library guide for more info (https://github.com/fzaninotto/Faker);
* After you created custom provider, for example:
*
* ~~~
* class Book extends \Faker\Provider\Base
* {
*
*
* public function title($nbWords = 5)
* {
* $sentence = $this->generator->sentence($nbWords);
* return mb_substr($sentence, 0, mb_strlen($sentence) - 1);
* }
*
*
* }
* ~~~
*
......@@ -131,6 +131,8 @@ use yii\helpers\VarDumper;
* ],
* ~~~
*
* @property \Faker\Generator $generator This property is read-only.
*
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0.0
*/
......
Yii Framework 2 gii extension Change Log
========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #1263: Fixed the issue that Gii and Debug modules might be affected by incompatible asset manager configuration (qiangxue)
- Bug #2314: Gii model generator does not generate correct relation type in some special case (qiangxue)
......
......@@ -21,7 +21,7 @@
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*",
"phpspec/php-diff": ">=1.0.2",
"bower-asset/typeahead.js": "0.10.* | ~0.10"
"bower-asset/typeahead.js": "0.10.*"
},
"autoload": {
"psr-4": {
......
Yii Framework 2 imagine extension Change Log
================================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- no changes in this release.
......
......@@ -19,7 +19,7 @@
],
"require": {
"yiisoft/yii2": "*",
"imagine/imagine": "v0.5.0"
"imagine/imagine": "0.5.*"
},
"autoload": {
"psr-4": {
......
Yii Framework 2 jui extension Change Log
========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Chg #1551: Jui datepicker has a new property `$dateFormat` which is used to set the clientOption `dateFormat`.
The new property does not use the datepicker formatting synax anymore but uses the same as the `yii\i18n\Formatter`
......
......@@ -19,7 +19,7 @@
],
"require": {
"yiisoft/yii2": "*",
"bower-asset/jquery-ui": "1.11.*@stable | ~1.11@stable"
"bower-asset/jquery-ui": "1.11.*@stable"
},
"autoload": {
"psr-4": {
......
Yii Framework 2 mongodb extension Change Log
============================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #2337: `yii\mongodb\Collection::buildLikeCondition()` fixed to escape regular expression (klimov-paul)
- Bug #3385: Fixed "The 'connected' property is deprecated" (samdark)
......
Yii Framework 2 redis extension Change Log
==========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #1311: Fixed storage and finding of `null` and boolean values (samdark, cebe)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
......
Yii Framework 2 smarty extension Change Log
===========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Enh #4619 (samdark, hwmaier)
- New functions:
......
Yii Framework 2 sphinx extension Change Log
===========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
......
Yii Framework 2 swiftmailer extension Change Log
================================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- no changes in this release.
......
Yii Framework 2 twig extension Change Log
=========================================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- no changes in this release.
2.0.0-rc September 27, 2014
---------------------------
- Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark)
- Bug #3767: Fixed repeated adding of extensions when using config. One may now pass extension instances as well (grachov)
......
Yii Framework 2 Change Log
==========================
2.0.0-rc under development
--------------------------
2.0.0 under development
-----------------------
- Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe)
- Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe)
- Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark)
- Enh: Added `yii\base\Application::loadedModules` (qiangxue)
2.0.0-rc September 27, 2014
---------------------------
- Bug #1263: Fixed the issue that Gii and Debug modules might be affected by incompatible asset manager configuration (qiangxue)
- Bug #2314: Gii model generator does not generate correct relation type in some special case (qiangxue)
......@@ -617,6 +626,7 @@ Yii Framework 2 Change Log
- New: Added various authentication methods, including `HttpBasicAuth`, `HttpBearerAuth`, `QueryParamAuth`, and `CompositeAuth` (qiangxue)
- New: Added `HtmlResponseFormatter` and `JsonResponseFormatter` (qiangxue)
2.0.0-alpha, December 1, 2013
-----------------------------
......
......@@ -12,13 +12,14 @@ The preferred way to install the Yii framework is through [composer](http://getc
Either run
```
php composer.phar require --prefer-dist "yiisoft/yii2 *"
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer require --prefer-dist "yiisoft/yii2 *"
```
or add
```json
"yiisoft/yii2": "*"
"yiisoft/yii2": "*",
```
to the require section of your composer.json.
......@@ -8,6 +8,20 @@ if you want to upgrade from version A to version C and there is
version B between A and C, you need to following the instructions
for both A and B.
Upgrade from Yii 2.0 RC
-----------------------
* If you've implemented `yii\rbac\ManagerInterface` you need to add implementation for new method `removeChildren()`.
* The input dates for datetime formatting are now assumed to be in UTC unless a timezone is explicitly given.
Before, the timezone assumed for input dates was the default timezone set by PHP which is the same as `Yii::$app->timeZone`.
This causes trouble because the formatter uses `Yii::$app->timeZone` as the default values for output so no timezone conversion
was possible. If your timestamps are stored in the database without a timezone identifier you have to ensure they are in UTC or
add a timezone identifier explicitly.
* `yii\bootstrap\Collapse` is now encoding labels by default. `encode` item option and global `encodeLabels` property were
introduced to disable it. Keys are no longer used as labels. You need to remove keys and use `label` item option instead.
Upgrade from Yii 2.0 Beta
-------------------------
......@@ -16,7 +30,7 @@ Upgrade from Yii 2.0 Beta
the composer-asset-plugin, *before* you update your project:
```
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta1"
php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta2"
```
You also need to add the following code to your project's `composer.json` file:
......
......@@ -180,6 +180,10 @@ abstract class Application extends Module
* This property is managed by the application. Do not modify this property.
*/
public $state;
/**
* @var array list of loaded modules indexed by their class names.
*/
public $loadedModules = [];
/**
......
......@@ -123,10 +123,6 @@ class Module extends ServiceLocator
* @var array child modules of this module
*/
private $_modules = [];
/**
* @var array list of currently requested modules indexed by their class names
*/
private static $_instances = [];
/**
......@@ -151,7 +147,7 @@ class Module extends ServiceLocator
public static function getInstance()
{
$class = get_called_class();
return isset(self::$_instances[$class]) ? self::$_instances[$class] : null;
return isset(Yii::$app->loadedModules[$class]) ? Yii::$app->loadedModules[$class] : null;
}
/**
......@@ -162,9 +158,9 @@ class Module extends ServiceLocator
public static function setInstance($instance)
{
if ($instance === null) {
unset(self::$_instances[get_called_class()]);
unset(Yii::$app->loadedModules[get_called_class()]);
} else {
self::$_instances[get_class($instance)] = $instance;
Yii::$app->loadedModules[get_class($instance)] = $instance;
}
}
......
......@@ -33,6 +33,7 @@ return [
'yii\base\InvalidConfigException' => YII2_PATH . '/base/InvalidConfigException.php',
'yii\base\InvalidParamException' => YII2_PATH . '/base/InvalidParamException.php',
'yii\base\InvalidRouteException' => YII2_PATH . '/base/InvalidRouteException.php',
'yii\base\InvalidValueException' => YII2_PATH . '/base/InvalidValueException.php',
'yii\base\Model' => YII2_PATH . '/base/Model.php',
'yii\base\ModelEvent' => YII2_PATH . '/base/ModelEvent.php',
'yii\base\Module' => YII2_PATH . '/base/Module.php',
......@@ -56,6 +57,7 @@ return [
'yii\behaviors\SluggableBehavior' => YII2_PATH . '/behaviors/SluggableBehavior.php',
'yii\behaviors\TimestampBehavior' => YII2_PATH . '/behaviors/TimestampBehavior.php',
'yii\caching\ApcCache' => YII2_PATH . '/caching/ApcCache.php',
'yii\caching\ArrayCache' => YII2_PATH . '/caching/ArrayCache.php',
'yii\caching\Cache' => YII2_PATH . '/caching/Cache.php',
'yii\caching\ChainedDependency' => YII2_PATH . '/caching/ChainedDependency.php',
'yii\caching\DbCache' => YII2_PATH . '/caching/DbCache.php',
......@@ -152,6 +154,7 @@ return [
'yii\helpers\BaseArrayHelper' => YII2_PATH . '/helpers/BaseArrayHelper.php',
'yii\helpers\BaseConsole' => YII2_PATH . '/helpers/BaseConsole.php',
'yii\helpers\BaseFileHelper' => YII2_PATH . '/helpers/BaseFileHelper.php',
'yii\helpers\BaseFormatConverter' => YII2_PATH . '/helpers/BaseFormatConverter.php',
'yii\helpers\BaseHtml' => YII2_PATH . '/helpers/BaseHtml.php',
'yii\helpers\BaseHtmlPurifier' => YII2_PATH . '/helpers/BaseHtmlPurifier.php',
'yii\helpers\BaseInflector' => YII2_PATH . '/helpers/BaseInflector.php',
......@@ -162,6 +165,7 @@ return [
'yii\helpers\BaseVarDumper' => YII2_PATH . '/helpers/BaseVarDumper.php',
'yii\helpers\Console' => YII2_PATH . '/helpers/Console.php',
'yii\helpers\FileHelper' => YII2_PATH . '/helpers/FileHelper.php',
'yii\helpers\FormatConverter' => YII2_PATH . '/helpers/FormatConverter.php',
'yii\helpers\Html' => YII2_PATH . '/helpers/Html.php',
'yii\helpers\HtmlPurifier' => YII2_PATH . '/helpers/HtmlPurifier.php',
'yii\helpers\Inflector' => YII2_PATH . '/helpers/Inflector.php',
......@@ -219,6 +223,7 @@ return [
'yii\rest\UrlRule' => YII2_PATH . '/rest/UrlRule.php',
'yii\rest\ViewAction' => YII2_PATH . '/rest/ViewAction.php',
'yii\test\ActiveFixture' => YII2_PATH . '/test/ActiveFixture.php',
'yii\test\ArrayFixture' => YII2_PATH . '/test/ArrayFixture.php',
'yii\test\BaseActiveFixture' => YII2_PATH . '/test/BaseActiveFixture.php',
'yii\test\DbFixture' => YII2_PATH . '/test/DbFixture.php',
'yii\test\Fixture' => YII2_PATH . '/test/Fixture.php',
......@@ -280,6 +285,7 @@ return [
'yii\web\RequestParserInterface' => YII2_PATH . '/web/RequestParserInterface.php',
'yii\web\Response' => YII2_PATH . '/web/Response.php',
'yii\web\ResponseFormatterInterface' => YII2_PATH . '/web/ResponseFormatterInterface.php',
'yii\web\ServerErrorHttpException' => YII2_PATH . '/web/ServerErrorHttpException.php',
'yii\web\Session' => YII2_PATH . '/web/Session.php',
'yii\web\SessionIterator' => YII2_PATH . '/web/SessionIterator.php',
'yii\web\TooManyRequestsHttpException' => YII2_PATH . '/web/TooManyRequestsHttpException.php',
......
......@@ -58,10 +58,10 @@
"yiisoft/yii2-composer": "*",
"ezyang/htmlpurifier": "4.6.*",
"cebe/markdown": "0.9.*",
"bower-asset/jquery": "2.1.*@stable | ~2.1@stable | ~1.11@stable",
"bower-asset/jquery.inputmask": "3.1.* | ~3.1",
"bower-asset/punycode": "1.3.* | ~1.3",
"bower-asset/yii2-pjax": "2.0.* | ~2.0"
"bower-asset/jquery": "2.1.*@stable | 1.11.*@stable",
"bower-asset/jquery.inputmask": "3.1.*",
"bower-asset/punycode": "1.3.*",
"bower-asset/yii2-pjax": "2.0.*"
},
"autoload": {
"psr-4": {"yii\\": ""}
......
......@@ -27,6 +27,9 @@ use yii\helpers\Console;
* where `<route>` is a route to a controller action and the params will be populated as properties of a command.
* See [[options()]] for details.
*
* @property string $help This property is read-only.
* @property string $helpSummary This property is read-only.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
......
......@@ -19,14 +19,14 @@ use yii\console\Exception;
* ~~~
* #see list of available components to flush
* yii cache
*
*
* #flush particular components specified by their names
* yii cache/flush first second third
*
*
* #flush all cache components that can be found in the system
* yii cache/flush-all
* ~~~
*
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0
......
......@@ -32,13 +32,13 @@ use yii\test\FixtureTrait;
*
* #append fixtures to already loaded
* yii fixture User --append
*
*
* #load fixtures with different namespace.
* yii fixture/load User --namespace=alias\my\custom\namespace\goes\here
* ~~~
*
* The `unload` sub-command can be used similarly to unload fixtures.
*
*
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0
*/
......
......@@ -118,8 +118,6 @@ use yii\caching\Cache;
* read-only.
* @property QueryBuilder $queryBuilder The query builder for the current DB connection. This property is
* read-only.
* @property array $queryCacheInfo The current query cache information, or null if query cache is not enabled.
* This property is read-only.
* @property Schema $schema The schema information for the database opened by this connection. This property
* is read-only.
* @property Connection $slave The currently active slave connection. Null is returned if there is slave
......
......@@ -120,7 +120,11 @@ class BaseArrayHelper
$next = array_shift($args);
foreach ($next as $k => $v) {
if (is_integer($k)) {
isset($res[$k]) ? $res[] = $v : $res[$k] = $v;
if (isset($res[$k])) {
$res[] = $v;
} else {
$res[$k] = $v;
}
} elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) {
$res[$k] = self::merge($res[$k], $v);
} else {
......
......@@ -30,17 +30,17 @@ return [
'{nFormatted} PiB' => '{nFormatted} PiB',
'{nFormatted} TB' => '{nFormatted} TB',
'{nFormatted} TiB' => '{nFormatted} TiB',
'{nFormatted} {n, plural, =1{byte} other{bytes}}' => '{nFormatted} {n, plural, =1{# bajt} other{# bajtov}}',
'{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}' => '{nFormatted} {n, plural, =1{gibibajt} other{gibibajtov}}',
'{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}' => '{nFormatted} {n, plural, =1{gigabajt} other{gigabajtov}}',
'{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}' => '{nFormatted} {n, plural, =1{kibibajt} other{kibibajtov}}',
'{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}' => '{nFormatted} {n, plural, =1{kilobajt} other{kilobajtov}}',
'{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}' => '{nFormatted} {n, plural, =1{mebibajt} other{mebibajtov}}',
'{nFormatted} {n, plural, =1{megabyte} other{megabytes}}' => '{nFormatted} {n, plural, =1{megabajt} other{megabajtov}}',
'{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}' => '{nFormatted} {n, plural, =1{pebibajt} other{pebibajtov}}',
'{nFormatted} {n, plural, =1{petabyte} other{petabytes}}' => '{nFormatted} {n, plural, =1{petabajt} other{petabajtov}}',
'{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}' => '{nFormatted} {n, plural, =1{tebibajt} other{tebibajtov}}',
'{nFormatted} {n, plural, =1{terabyte} other{terabytes}}' => '{nFormatted} {n, plural, =1{terabajt} other{terabajtov}}',
'{nFormatted} {n, plural, =1{byte} other{bytes}}' => '{nFormatted} {n, plural, =1{bajt} =2{bajty} =3{bajty} =4{bajty} other{bajtov}}',
'{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}' => '{nFormatted} {n, plural, =1{gibibajt} =2{gibibajty} =3{gibibajty} =4{gibibajty} other{gibibajtov}}',
'{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}' => '{nFormatted} {n, plural, =1{gigabajt} =2{gigabajty} =3{gigabajty} =4{gigabajty} other{gigabajtov}}',
'{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}' => '{nFormatted} {n, plural, =1{kibibajt} =2{kibibajty} =3{kibibajty} =4{kibibajty} other{kibibajtov}}',
'{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}' => '{nFormatted} {n, plural, =1{kilobajt} =2{kilobajty} =3{kilobajty} =4{kilobajty} other{kilobajtov}}',
'{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}' => '{nFormatted} {n, plural, =1{mebibajt} =2{mebibajty} =3{mebibajty} =4{mebibajty} other{mebibajtov}}',
'{nFormatted} {n, plural, =1{megabyte} other{megabytes}}' => '{nFormatted} {n, plural, =1{megabajt} =2{megabajty} =3{megabajty} =4{megabajty} other{megabajtov}}',
'{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}' => '{nFormatted} {n, plural, =1{pebibajt} =2{pebibajty} =3{pebibajty} =4{pebibajty} other{pebibajtov}}',
'{nFormatted} {n, plural, =1{petabyte} other{petabytes}}' => '{nFormatted} {n, plural, =1{petabajt} =2{petabajty} =3{petabajty} =4{petabajty} other{petabajtov}}',
'{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}' => '{nFormatted} {n, plural, =1{tebibajt} =2{tebibajty} =3{tebibajty} =4{tebibajty} other{tebibajtov}}',
'{nFormatted} {n, plural, =1{terabyte} other{terabytes}}' => '{nFormatted} {n, plural, =1{terabajt} =2{terabajty} =3{terabajty} =4{terabajty} other{terabajtov}}',
'(not set)' => '(nie je nastavené)',
'An internal server error occurred.' => 'Vyskytla sa interná chyba servera.',
'Are you sure you want to delete this item?' => 'Skutočne chcete odstrániť tento záznam?',
......
......@@ -542,6 +542,16 @@ class DbManager extends BaseManager
/**
* @inheritdoc
*/
public function removeChildren($parent)
{
return $this->db->createCommand()
->delete($this->itemChildTable, ['parent' => $parent->name])
->execute() > 0;
}
/**
* @inheritdoc
*/
public function hasChild($parent, $child)
{
return (new Query)
......
......@@ -146,6 +146,14 @@ interface ManagerInterface
public function removeChild($parent, $child);
/**
* Removed all children form their parent.
* Note, the children items are not deleted. Only the parent-child relationships are removed.
* @param Item $parent
* @return boolean whether the removal is successful
*/
public function removeChildren($parent);
/**
* Returns a value indicating whether the child already exists for the parent.
* @param Item $parent
* @param Item $child
......
......@@ -218,6 +218,20 @@ class PhpManager extends BaseManager
/**
* @inheritdoc
*/
public function removeChildren($parent)
{
if (isset($this->children[$parent->name])) {
unset($this->children[$parent->name]);
$this->saveItems();
return true;
} else {
return false;
}
}
/**
* @inheritdoc
*/
public function hasChild($parent, $child)
{
return isset($this->children[$parent->name][$child->name]);
......
......@@ -13,7 +13,7 @@ use yii\base\InvalidConfigException;
/**
* ArrayFixture represents arbitrary fixture that can be loaded from PHP files.
*
*
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0
*/
......
......@@ -31,6 +31,9 @@ use yii\helpers\Url;
* ]
* ```
*
* @property AssetConverterInterface $converter The asset converter. Note that the type of this property
* differs in getter and setter. See [[getConverter()]] and [[setConverter()]] for details.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
......
......@@ -142,7 +142,7 @@ class HeaderCollection extends Object implements \IteratorAggregate, \ArrayAcces
/**
* Removes a header.
* @param string $name the name of the header to be removed.
* @return string the value of the removed header. Null is returned if the header does not exist.
* @return array the value of the removed header. Null is returned if the header does not exist.
*/
public function remove($name)
{
......@@ -150,7 +150,6 @@ class HeaderCollection extends Object implements \IteratorAggregate, \ArrayAcces
if (isset($this->_headers[$name])) {
$value = $this->_headers[$name];
unset($this->_headers[$name]);
return $value;
} else {
return null;
......
......@@ -65,7 +65,6 @@ use yii\helpers\StringHelper;
* @property string $queryString Part of the request URL that is after the question mark. This property is
* read-only.
* @property string $rawBody The request body. This property is read-only.
* @property string $rawCsrfToken The random token for CSRF validation. This property is read-only.
* @property string $referrer URL referrer, null if not present. This property is read-only.
* @property string $scriptFile The entry script file path.
* @property string $scriptUrl The relative URL of the entry script.
......
......@@ -35,6 +35,7 @@ use yii\helpers\StringHelper;
* ~~~
*
* @property CookieCollection $cookies The cookie collection. This property is read-only.
* @property string $downloadHeaders The attachment file name. This property is write-only.
* @property HeaderCollection $headers The header collection. This property is read-only.
* @property boolean $isClientError Whether this response indicates a client error. This property is
* read-only.
......
......@@ -625,8 +625,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
* @param mixed $defaultValue value to be returned if the flash message does not exist.
* @param boolean $delete whether to delete this flash message right after this method is called.
* If false, the flash message will be automatically deleted in the next request.
* @return mixed the flash message
* @return mixed the flash message or an array of messages if addFlash was used
* @see setFlash()
* @see addFlash()
* @see hasFlash()
* @see getAllFlashes()
* @see removeFlash()
......@@ -664,13 +665,16 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*
* With the above code you can use the [bootstrap alert][] classes such as `success`, `info`, `danger`
* as the flash message key to influence the color of the div.
*
* Note that if you use [[addFlash()]], `$message` will be an array, and you will have to adjust the above code.
*
* [bootstrap alert]: http://getbootstrap.com/components/#alerts
*
* @param boolean $delete whether to delete the flash messages right after this method is called.
* If false, the flash messages will be automatically deleted in the next request.
* @return array flash messages (key => message).
* @return array flash messages (key => message or key => [message1, message2]).
* @see setFlash()
* @see addFlash()
* @see getFlash()
* @see hasFlash()
* @see removeFlash()
......@@ -712,6 +716,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
* regardless if it is accessed or not. If true (default value), the flash message will remain until after
* it is accessed.
* @see getFlash()
* @see addFlash()
* @see removeFlash()
*/
public function setFlash($key, $value = true, $removeAfterAccess = true)
......@@ -732,6 +737,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
* regardless if it is accessed or not. If true (default value), the flash message will remain until after
* it is accessed.
* @see getFlash()
* @see setFlash()
* @see removeFlash()
*/
public function addFlash($key, $value = true, $removeAfterAccess = true)
......@@ -758,6 +764,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
* @return mixed the removed flash message. Null if the flash message does not exist.
* @see getFlash()
* @see setFlash()
* @see addFlash()
* @see removeAllFlashes()
*/
public function removeFlash($key)
......@@ -777,6 +784,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
* by this method.
* @see getFlash()
* @see setFlash()
* @see addFlash()
* @see removeFlash()
*/
public function removeAllFlashes()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment