Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminating beginPage() and endPage() in layouts #1548

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework/yii/base/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function render($view, $params = [])
$output = $this->getView()->render($view, $params, $this);
$layoutFile = $this->findLayoutFile($this->getView());
if ($layoutFile !== false) {
return $this->getView()->renderFile($layoutFile, ['content' => $output], $this);
return $this->getView()->renderLayoutFile($layoutFile, ['content' => $output], $this);
} else {
return $output;
}
Expand Down
60 changes: 40 additions & 20 deletions framework/yii/base/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,46 @@ public function renderFile($viewFile, $params = [], $context = null)
return $output;
}

/**
* Renders a layout file.
*
* @param string $viewFile the layout file. This can be either a file path or a path alias.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @param object $context the context that the view should use for rendering the view. If null,
* existing [[context]] will be used.
* @return string the rendering result
*/
public function renderLayoutFile($layoutFile, $params = [], $context = null)
{
ob_start();
ob_implicit_flush(false);
$this->trigger(self::EVENT_BEGIN_PAGE);

echo $this->renderFile($layoutFile, $params, $context);

$this->trigger(self::EVENT_END_PAGE);

$content = ob_get_clean();
foreach (array_keys($this->assetBundles) as $bundle) {
$this->registerAssetFiles($bundle);
}
echo strtr($content, [
self::PH_HEAD => $this->renderHeadHtml(),
self::PH_BODY_BEGIN => $this->renderBodyBeginHtml(),
self::PH_BODY_END => $this->renderBodyEndHtml(),
]);

unset(
$this->metaTags,
$this->linkTags,
$this->css,
$this->cssFiles,
$this->js,
$this->jsFiles
);
return $content;
}

/**
* This method is invoked right before [[renderFile()]] renders a view file.
* The default implementation will trigger the [[EVENT_BEFORE_RENDER]] event.
Expand Down Expand Up @@ -438,24 +478,4 @@ public function endCache()
{
FragmentCache::end();
}

/**
* Marks the beginning of a page.
*/
public function beginPage()
{
ob_start();
ob_implicit_flush(false);

$this->trigger(self::EVENT_BEGIN_PAGE);
}

/**
* Marks the ending of a page.
*/
public function endPage()
{
$this->trigger(self::EVENT_END_PAGE);
ob_end_flush();
}
}
10 changes: 8 additions & 2 deletions framework/yii/caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ abstract class Cache extends Component implements \ArrayAccess
* you are using [[Dependency|cache dependency]], because it relies on data serialization.
*/
public $serializer;

/**
* @var int Default number of seconds in which the cached value will expire
*/
public $expire=0;

/**
* Initializes the application component.
Expand Down Expand Up @@ -201,8 +204,11 @@ public function mget($keys)
* This parameter is ignored if [[serializer]] is false.
* @return boolean whether the value is successfully stored into cache
*/
public function set($key, $value, $expire = 0, $dependency = null)
public function set($key, $value, $expire = null, $dependency = null)
{
if ($expire === null) {
$expire = abs((int)$this->expire);
}
if ($dependency !== null && $this->serializer !== false) {
$dependency->evaluateDependency($this);
}
Expand Down
27 changes: 0 additions & 27 deletions framework/yii/web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,6 @@ public function setAssetManager($value)
$this->_assetManager = $value;
}

/**
* Marks the ending of an HTML page.
*/
public function endPage()
{
$this->trigger(self::EVENT_END_PAGE);

$content = ob_get_clean();
foreach (array_keys($this->assetBundles) as $bundle) {
$this->registerAssetFiles($bundle);
}
echo strtr($content, [
self::PH_HEAD => $this->renderHeadHtml(),
self::PH_BODY_BEGIN => $this->renderBodyBeginHtml(),
self::PH_BODY_END => $this->renderBodyEndHtml(),
]);

unset(
$this->metaTags,
$this->linkTags,
$this->css,
$this->cssFiles,
$this->js,
$this->jsFiles
);
}

/**
* Registers all files provided by an asset bundle including depending bundles files.
* Removes a bundle from [[assetBundles]] once files are registered.
Expand Down