Commit effd47db by Abderrahim Bajja

Merge remote-tracking branch 'upstream/master'

Update from remote
parents 8dead867 60b38a1a
Кэширование
=======
Кэширование — это простой и эффективный способ повысить производительность веб-приложения. Сохраняя относительно
статичные данные в кэше и извлекая их из кэша, когда потребуется, мы экономим время, затрачиваемое на генерацию
данных с нуля каждый раз.
Кэширование может использоваться на различных уровнях веб-приложения. На стороне сервера, на более низшем уровне мы
используем кэширование для хранения основных данных, таких как список последних статьей запрашиваемых из базы данных;
и на более высоком уровне, кэш может использоваться для хранения фрагментов или целых веб-страниц, например как результат
рендеринга последних статьей. На стороне клиента может использоваться HTTP-кэширование, чтобы сохранить содержимое
недавно посещенных страниц в кэше браузера.
Yii поддерживает все эти механизмы кэширования:
* [Кэширование данных](caching-data.md)
* [Кэширование фрагментов](caching-fragment.md)
* [Кэширование страниц](caching-page.md)
* [HTTP-кэширование](caching-http.md)
......@@ -136,8 +136,20 @@ $component->attachBehaviors([
]);
```
You may also attach behaviors through [configurations](concept-configurations.md). For more details, please
refer to the [Configurations](concept-configurations.md#configuration-format) section.
You may also attach behaviors through [configurations](concept-configurations.md) like the following. For more details,
please refer to the [Configurations](concept-configurations.md#configuration-format) section.
```php
[
'as myBehavior2' => MyBehavior::className(),
'as myBehavior3' => [
'class' => MyBehavior::className(),
'prop1' => 'value1',
'prop2' => 'value2',
],
]
```
Detaching Behaviors <a name="detaching-behaviors"></a>
......
......@@ -162,6 +162,18 @@ $foo->on(Foo::EVENT_HELLO, function ($event) {
}, $data, false);
```
Besides calling the `on()` method, you may also attach event handlers in [configurations](concept-configurations.md)
like the following. For more details, please refer to the [Configurations](concept-configurations.md#configuration-format)
section.
```php
[
'on hello' => function ($event) {
echo 'hello event is triggered';
}
]
```
Detaching Event Handlers <a name="detaching-event-handlers"></a>
------------------------
......
......@@ -2,10 +2,13 @@ Controllers
===========
Controllers are part of the [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) architecture.
They are objects responsible for processing requests and generating responses. In particular, after
taking over the control from [applications](structure-applications.md), controllers will analyze incoming request data,
pass them to [models](structure-models.md), inject model results into [views](structure-views.md),
and finally generate outgoing responses.
They are objects of classes extending from [[yii\base\Controller]] and are responsible for processing requests and
generating responses. In particular, after taking over the control from [applications](structure-applications.md),
controllers will analyze incoming request data, pass them to [models](structure-models.md), inject model results
into [views](structure-views.md), and finally generate outgoing responses.
## Actions <a name="actions"></a>
Controllers are composed by *actions* which are the most basic units that end users can address and request for
execution. A controller can have one or multiple actions.
......
......@@ -21,7 +21,7 @@ structure-controllers.md | Yes
structure-views.md | Yes
structure-models.md | Yes
structure-modules.md | Yes
structure-filters.md |
structure-filters.md | Yes
structure-widgets.md |
structure-assets.md |
structure-extensions.md |
......
......@@ -21,7 +21,7 @@ use yii\base\InvalidConfigException;
* use yii\bootstrap\ActiveForm;
*
* $form = ActiveForm::begin(['layout' => 'horizontal'])
* ```
* ```
*
* This will set default values for the [[yii\bootstrap\ActiveField|ActiveField]]
* to render horizontal form fields. In particular the [[yii\bootstrap\ActiveField::template|template]]
......
......@@ -51,6 +51,7 @@ Yii Framework 2 Change Log
- Bug #3909: `Html::to()` should not prefix base URL to URLs that already contain scheme (qiangxue)
- Bug #3934: yii.handleAction() in yii.js does not correctly detect if a hyperlink contains useful URL or not (joni-jones, qiangxue)
- Bug #3968: Messages logged in shutdown functions are not handled (qiangxue)
- Bug #3996: Traversing `Yii::$app->session` may cause a PHP error (qiangxue)
- Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark)
- Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
- Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
......
......@@ -12,11 +12,11 @@ use yii\base\ActionFilter;
use yii\base\Action;
/**
* The HttpCache provides functionality for caching via HTTP Last-Modified and Etag headers.
* HttpCache implements client-side caching by utilizing the `Last-Modified` and `Etag` HTTP headers.
*
* It is an action filter that can be added to a controller and handles the `beforeAction` event.
*
* To use AccessControl, declare it in the `behaviors()` method of your controller class.
* To use HttpCache, declare it in the `behaviors()` method of your controller class.
* In the following example the filter will be applied to the `list`-action and
* the Last-Modified header will contain the date of the last update to the user table in the database.
*
......@@ -24,7 +24,7 @@ use yii\base\Action;
* public function behaviors()
* {
* return [
* 'httpCache' => [
* [
* 'class' => 'yii\filters\HttpCache',
* 'only' => ['index'],
* 'lastModified' => function ($action, $params) {
......
......@@ -13,15 +13,14 @@ use yii\base\Action;
use yii\caching\Dependency;
/**
* The PageCache provides functionality for whole page caching
* PageCache implements server-side caching of whole pages.
*
* It is an action filter that can be added to a controller and handles the `beforeAction` event.
*
* To use PageCache, declare it in the `behaviors()` method of your controller class.
* In the following example the filter will be applied to the `list`-action and
* In the following example the filter will be applied to the `index` action and
* cache the whole page for maximum 60 seconds or until the count of entries in the post table changes.
* It also stores different versions of the page depended on the route ([[varyByRoute]] is true by default),
* the application language and user id.
* It also stores different versions of the page depending on the application language.
*
* ~~~
* public function behaviors()
......
......@@ -415,7 +415,7 @@ class BaseInflector
public static function slug($string, $replacement = '-', $lowercase = true)
{
$string = static::transliterate($string);
$string = preg_replace('/[^a-zA-Z=\s—–-]+/u', '', $string);
$string = preg_replace('/[^a-zA-Z0-9=\s—–-]+/u', '', $string);
$string = preg_replace('/[=\s—–-]+/u', $replacement, $string);
$string = trim($string, $replacement);
......
......@@ -507,6 +507,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*/
public function getIterator()
{
$this->open();
return new SessionIterator;
}
......@@ -516,6 +517,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*/
public function getCount()
{
$this->open();
return count($_SESSION);
}
......@@ -539,7 +541,6 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
public function get($key, $defaultValue = null)
{
$this->open();
return isset($_SESSION[$key]) ? $_SESSION[$key] : $defaultValue;
}
......
......@@ -126,7 +126,7 @@ class InflectorTest extends TestCase
{
$data = [
'' => '',
'hello world' => 'hello-world',
'hello world 123' => 'hello-world-123',
'remove.!?[]{}…symbols' => 'removesymbols',
'minus-sign' => 'minus-sign',
'mdash—sign' => 'mdash-sign',
......
......@@ -13,16 +13,35 @@ use yii\widgets\Breadcrumbs;
class BreadcrumbsTest extends \yiiunit\TestCase
{
private $breadcrumbs;
private $app;
public function setUp()
{
$this->app = $this->mockApplication();
Yii::setAlias('@testWeb', '/');
Yii::setAlias('@testWebRoot', '@yiiunit/data/web');
// dirty way to have Request object not throwing exception when running testHomeLinkNull()
$_SERVER['SCRIPT_FILENAME'] = "index.php";
$_SERVER['SCRIPT_NAME'] = "index.php";
$this->mockApplication([], 'yii\web\Application');
$this->breadcrumbs = new Breadcrumbs();
}
public function testHomeLinkNull()
{
$this->breadcrumbs->homeLink = null;
$this->breadcrumbs->links = ['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page'];
$expectedHtml = "<ul class=\"breadcrumb\"><li><a href=\"./index.php\">Home</a></li>\n"
. "<li class=\"active\">My Home Page</li>\n"
. "<li class=\"active\">http://my.example.com/yii2/link/page</li>\n"
. "</ul>";
ob_start();
$this->breadcrumbs->run();
$actualHtml = ob_get_contents();
ob_end_clean();
$this->assertEquals($expectedHtml, $actualHtml);
}
public function testEmptyLinks()
{
$this->assertNull($this->breadcrumbs->run());
......
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