Quantcast

Why doesn't JsonView trigger callbacks?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Why doesn't JsonView trigger callbacks?

Lucho Molina-2
I was playing around with JsonView and the PaginatorHelper and noticed that the data returned by $this->Paginator->next() was different to the one returned by the same method when using the normal (HTML) view. 

Digging into the code, I found out that the JsonView doesn't trigger the beforeRender callback. Why is that? is this a bug or is it meant to be like that by design?

Specifically speaking, the render method of the View class triggers the callbacks like this:

464 $this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($viewFileName)));
465 $this->Blocks->set('content', $this->_render($viewFileName));
466 $this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($viewFileName)));

Whereas JsonView->render() will just return the $content without triggering the callbacks. 

I'm on version 2.1.3, btw.

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Why doesn't JsonView trigger callbacks?

Lucho Molina-2
[Tumbleweed] 

:P

On Monday, August 13, 2012 11:28:53 AM UTC-5, Lucho Molina wrote:
I was playing around with JsonView and the PaginatorHelper and noticed that the data returned by $this->Paginator->next() was different to the one returned by the same method when using the normal (HTML) view. 

Digging into the code, I found out that the JsonView doesn't trigger the beforeRender callback. Why is that? is this a bug or is it meant to be like that by design?

Specifically speaking, the render method of the View class triggers the callbacks like this:

464 $this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($viewFileName)));
465 $this->Blocks->set('content', $this->_render($viewFileName));
466 $this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($viewFileName)));

Whereas JsonView->render() will just return the $content without triggering the callbacks. 

I'm on version 2.1.3, btw.

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Why doesn't JsonView trigger callbacks?

Ceeram
https://github.com/cakephp/cakephp/pull/777

Keep an eye on this one id say :)

On Wednesday, August 15, 2012 12:57:53 AM UTC+2, Lucho Molina wrote:
[Tumbleweed] 

:P

On Monday, August 13, 2012 11:28:53 AM UTC-5, Lucho Molina wrote:
I was playing around with JsonView and the PaginatorHelper and noticed that the data returned by $this->Paginator->next() was different to the one returned by the same method when using the normal (HTML) view. 

Digging into the code, I found out that the JsonView doesn't trigger the beforeRender callback. Why is that? is this a bug or is it meant to be like that by design?

Specifically speaking, the render method of the View class triggers the callbacks like this:

464 $this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($viewFileName)));
465 $this->Blocks->set('content', $this->_render($viewFileName));
466 $this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($viewFileName)));

Whereas JsonView->render() will just return the $content without triggering the callbacks. 

I'm on version 2.1.3, btw.

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Loading...