Skip to content

Commit

Permalink
Fix#18328: Yii::warning() raised on file register after View::endBody…
Browse files Browse the repository at this point in the history
…() has been moved to View::endPage() (#18975)

Co-authored-by: Mehdi Achour <machour@gmail.com>
  • Loading branch information
perlexed and machour committed Oct 25, 2021
1 parent d27fb96 commit e294c23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Yii Framework 2 Change Log
------------------------

- Bug #18798: Fix `StringHelper::dirname()` when passing string with a trailing slash (perlexed)
- Enh #18328: Raise warning when trying to register a file after `View::endBody()` has been called (perlexed)
- Enh #18328: Raise warning when trying to register a file after `View::endPage()` has been called (perlexed)
- 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)
- Enh #18826: Add ability to turn the sorting off for a clicked column in GridView with multisort (ditibal)
Expand Down
12 changes: 6 additions & 6 deletions framework/web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ class View extends \yii\base\View
private $_assetManager;

/**
* Whether [[endBody()]] has been called
* Whether [[endPage()]] has been called and all files have been registered
* @var bool
*/
private $_isBodyEnded = false;
private $_isPageEnded = false;


/**
Expand Down Expand Up @@ -165,8 +165,6 @@ public function endBody()
$this->trigger(self::EVENT_END_BODY);
echo self::PH_BODY_END;

$this->_isBodyEnded = true;

foreach (array_keys($this->assetBundles) as $bundle) {
$this->registerAssetFiles($bundle);
}
Expand All @@ -182,6 +180,8 @@ public function endPage($ajaxMode = false)
{
$this->trigger(self::EVENT_END_PAGE);

$this->_isPageEnded = true;

$content = ob_get_clean();

echo strtr($content, [
Expand Down Expand Up @@ -498,8 +498,8 @@ private function registerFile($type, $url, $options = [], $key = null)
}
$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 ($this->_isPageEnded) {
Yii::warning('You\'re trying to register a file after View::endPage() has been called');
}

if (empty($depends)) {
Expand Down

0 comments on commit e294c23

Please sign in to comment.