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.

[SOLVED]Using Phalcon to create a project using HTML5 History

Hi, I was searching the web for a framework to build my new project and found Phalcon which seems to be really interesting. I started to read its documentation, trying samples and build little applications to learn how it works.

But, there is one more thing I'd like to do before using Phalcon. I need HTML5 history to work on my application. This means that I'd like to show HTML or JSON depending on http headers. And I'd like to avoid creating the 3 same lines of code in every action.

For example : I go to : -> Call SearchController::queryAction() and send HTML response I go to :, fill the form query and click "Search", jquery ajax call using ajax http header and get the response which would contain for example :

    "title" : "this is a test",
    "body" : "<div>[...]</div>"
    "url" : ""

And use pushstate.

The problem is that I need this kind of double response type for almost all my controller (if not all of them).

Thanks, cylessia


Hi! I solved this problem in my project. On event 'afterExecuteRoute' in base controller I check ajax headers on request. After I attach handler on 'view::afterRender' event, where rendered content wrapped by json. See code here:

Good luck!


This is exactly what I needed, thanks ! I figured out another way by implementing a manual bootstrap but it became to be messy and complicated.