Workaround for double-template rendering with forward() plug-in. #2206

Merged
merged 1 commit into from Aug 20, 2012

Conversation

Projects
None yet
3 participants
@demiankatz
Contributor

demiankatz commented Aug 20, 2012

If a caller returns the value of $this->forward()->dispatch() in a controller action while the InjectViewModelListener is active, the same view model gets attached to the layout twice, and the PHP template will be rendered twice, wasting resources and possibly causing strange side effects. This commit detaches the problem listener before dispatching a forwarded action so that the output of dispatch() can be safely returned by the calling action. It also provides a generic, extensible mechanism for detaching other listeners in different use cases.

If a caller returns the value of $this->forward()->dispatch() in a co…
…ntroller action while the InjectViewModelListener is active, the same view model gets attached to the layout twice, and the PHP template will be rendered twice, wasting resources and possibly causing strange side effects. This commit detaches the problem listener before dispatching a forwarded action. It also provides a generic, extensible mechanism for detaching other listeners in different use cases.
@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Aug 20, 2012

This pull request passes (merged 0b8fc7a into 5dd58b8).

This pull request passes (merged 0b8fc7a into 5dd58b8).

+ public function getListenersToDetach()
+ {
+ // If a blacklist has not been explicitly set, return the default:
+ if (is_null($this->listenersToDetach)) {

This comment has been minimized.

@weierophinney

weierophinney Aug 20, 2012

Member

The convention within the framework is to use "null === $this->listenersToDetach", or, if you despise yoda conditions, "$this->listenersToDetach === null", instead of is_null().

@weierophinney

weierophinney Aug 20, 2012

Member

The convention within the framework is to use "null === $this->listenersToDetach", or, if you despise yoda conditions, "$this->listenersToDetach === null", instead of is_null().

+ array(
+ 'id' => 'Zend\Stdlib\DispatchableInterface',
+ 'event' => MvcEvent::EVENT_DISPATCH,
+ 'class' => 'Zend\Mvc\View\Http\InjectViewModelListener'

This comment has been minimized.

@weierophinney

weierophinney Aug 20, 2012

Member

Add a comma after last element in array (allows re-ordering or adding new items with minimal changeset in the VCS).

@weierophinney

weierophinney Aug 20, 2012

Member

Add a comma after last element in array (allows re-ordering or adding new items with minimal changeset in the VCS).

weierophinney added a commit that referenced this pull request Aug 20, 2012

[#2206] consistency fixes
- Per comments on issue.
@weierophinney

This comment has been minimized.

Show comment
Hide comment
@weierophinney

weierophinney Aug 20, 2012

Member

I took care of all suggestions above when merging.

Member

weierophinney commented Aug 20, 2012

I took care of all suggestions above when merging.

@weierophinney weierophinney merged commit 0b8fc7a into zendframework:master Aug 20, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment