We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Next Version of Phalcon

I am a novice in phalcon,(but I have 4 years experience in web development)

I have a suggestion for the development of the next version

Please add more tools to communicate with (Ajax|Ajax Based Apps) to Phalcon, Tools for

connect to Javascript frameworks (.e.g EmberJs,AngularJs,reactJs...)

Tools for leading the development inside the JSON Outputs.

Eventually,make phalcon Ajax&Json Friendly

I think it will be make more popular phalcon,Will be more attractive by adding These tools!

Now We can Dev Apps inside Ajax but it not easy and prefect!

I know little(30%-40%) of the Zephir-language ,I try to join in the near future to gather developers,If I can be worthy :)

Thank you for free Efforts :)

Phalcon will have an eternal effect...

edited Apr '16

You are very right about this. I would love to see all those ajax tools and widgets like in Yii2. More stuff out of the box is nice, but right now is more important to make phalcon work properly with all db connectors

edited Apr '16
connect to Javascript frameworks (.e.g EmberJs,AngularJs,reactJs...)

What you mean ? Phalcon is very json&ajax friendly. I don't know how you want to connect both, one is server side second is frontend, i don't see any connection. It's to developer how he is connecting to his backend and vice versa.

@Wojciech if you take a look on Yii2 you can extend it with extensions and widgets, giving you these connections out of the box without having to do it yourself. Is something nice to have, but not such a big deal.

edited Apr '16
connect to Javascript frameworks (.e.g EmberJs,AngularJs,reactJs...)

What you mean ? Phalcon is very json&ajax friendly. I don't know how you want to connect both, one is server side second is frontend, i don't see any connection. It's to developer how he is connecting to his backend and vice versa.

For Example:

When We would create an app that it is a form , Submiting by ajax & we will return errors,messages,flash-messages as a JSON string & We have many problems for Dev This.

To bypass this, I created an JSONResponse. Every exception (this includes model validation messages) are incorporated to this return. Pretty easy to do, but not out of the box...

connect to Javascript frameworks (.e.g EmberJs,AngularJs,reactJs...)

What you mean ? Phalcon is very json&ajax friendly. I don't know how you want to connect both, one is server side second is frontend, i don't see any connection. It's to developer how he is connecting to his backend and vice versa.

For Example:

When We would create an app that it is a form , Submiting by ajax & we will return errors,messages,flash-messages as a JSON string & We have many problems for Dev This.



5.7k
Accepted
answer

Can't this be done line this today?

echo json_encode(array(
    'errors' => array('x component' => 'foo error encountered'),
    'system_flash_messages' => array('flash message 1', 'generated message 2')
));

My output format may be different from your output format though, and the example here means repeating this code all over the place, which means it's better off as a service, which is a class that you add stuff to, then implement toArray(), toJson().

$app->get('/some/route', function () use ($app) {
    try {
        // ...
        $app->myOutputHandler->addData('some message or data when success');
    } catch (Exception $e) {
        $app->myOutputHandler->addError($e->getMessage());
    }

    // ...
    // then at the end of a route
    return $app->myOutputHandler->toArray();
}

// Phalcon has this event handler that will run **after** each route is executed
$app->after(function () use ($app) {
    echo json_encode($app->getReturnedValue());
});
edited Apr '16

Guys, what's wrong with

$this->response->setJsonContent() ?

Im using it everywhere in my angular app.

edited May '16

Guys, what's wrong with

$this->response->setJsonContent() ?

Im using it everywhere in my angular app.

In Phalcon 2.0.x you still need to set "Content-Type" HTTP header to application/json.
setJsonContent() method is just a wrapper around PHP json_encode, thus it will accept any arguments or flags like JSON_NUMERIC_CHECK etc.

I always tend to use this method, since it gives better overall framework-like style to an application.