Browse Source

Fix #18328: Raise warning when trying to register a file after `View::endBody()` has been called

tags/2.0.44
Aleksandr Bogatikov 3 years ago committed by GitHub
parent
commit
b757d25c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 12
      framework/web/View.php

1
framework/CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.44 under development 2.0.44 under development
------------------------ ------------------------
- Enh #18328: Raise warning when trying to register a file after `View::endBody()` has been called (perlexed)
- Enh #18812: Added error messages and optimized "error" methods in `yii\helpers\BaseJson` (WinterSilence, samdark) - Enh #18812: Added error messages and optimized "error" methods in `yii\helpers\BaseJson` (WinterSilence, samdark)
- Chg #18823: Rollback changes #18806 in `yii\validators\ExistValidator::checkTargetRelationExistence()` (WinterSilence) - Chg #18823: Rollback changes #18806 in `yii\validators\ExistValidator::checkTargetRelationExistence()` (WinterSilence)
- Enh #18826: Add ability to turn the sorting off for a clicked column in GridView with multisort (ditibal) - Enh #18826: Add ability to turn the sorting off for a clicked column in GridView with multisort (ditibal)

12
framework/web/View.php

@ -133,6 +133,12 @@ class View extends \yii\base\View
private $_assetManager; private $_assetManager;
/**
* Whether [[endBody()]] has been called
* @var bool
*/
private $_isBodyEnded = false;
/** /**
* Marks the position of an HTML head section. * Marks the position of an HTML head section.
@ -159,6 +165,8 @@ class View extends \yii\base\View
$this->trigger(self::EVENT_END_BODY); $this->trigger(self::EVENT_END_BODY);
echo self::PH_BODY_END; echo self::PH_BODY_END;
$this->_isBodyEnded = true;
foreach (array_keys($this->assetBundles) as $bundle) { foreach (array_keys($this->assetBundles) as $bundle) {
$this->registerAssetFiles($bundle); $this->registerAssetFiles($bundle);
} }
@ -490,6 +498,10 @@ class View extends \yii\base\View
} }
$appendTimestamp = ArrayHelper::remove($options, 'appendTimestamp', $assetManagerAppendTimestamp); $appendTimestamp = ArrayHelper::remove($options, 'appendTimestamp', $assetManagerAppendTimestamp);
if ($this->_isBodyEnded) {
Yii::warning('You\'re trying to register a file after View::endBody() has been called');
}
if (empty($depends)) { if (empty($depends)) {
// register directly without AssetManager // register directly without AssetManager
if ($appendTimestamp && Url::isRelative($url)) { if ($appendTimestamp && Url::isRelative($url)) {

Loading…
Cancel
Save