Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Which event is best for accomplishing my goal?

I am implementing a demo project using Phalcon and jQuery PJAX.

Currently, I am using the beforeExecuteRoute on a base controller to disable the layouts on an ajax response, allowing just the view to be returned. So I am checking if the request is an ajax/pjax response, and if it is, I am disabling the layouts.

I want to disable the layouts at the last minute before the view begins being processed, to allow individual controllers to override the fact that it is pjax and force a hard refresh.

What event would be the best option for updating this before the view is sent? afterDispatch? afterDispatchLoop? I am unsure of the difference between those two. Maybe afterExecuteRoute?

I would appreciate any guidance and I'm happy to clarify if needed.

Thank you



19.7k
Accepted
answer

Use the Events Manager to process things in the beforeRender event of the view.

http://docs.phalconphp.com/en/latest/reference/views.html#view-events

edited Nov '14

Use the Events Manager to process things in the beforeRender event of the view.

http://docs.phalconphp.com/en/latest/reference/views.html#view-events

Events manager ended up working pretty well.

However, I was shown a better way for this specific scenario in this post.

Turns out afterExecuteRoute is a good choice for executing code before the view is rendered and it's a bit cleaner for something as simple as what I was trying to accomplish.

Thanks!