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

Format model results before send to client

i am building project restful api with phalcon micro! So any way format result before send to client ?

Example My category table with column

    id => int (auto increment)
    name => varchar 256
    status => int 11
    sort_order => int 11

in my code

    $result = Model:findFirst(1);
    $response->json($result->toArray());

but in client id , status and sort_order is string type

i am ask for best way format in model after query .



4.2k
Accepted
answer
edited Oct '18

You have to enable following PDO options when connection to your database:

'options' => [
\PDO::ATTR_EMULATE_PREPARES => false,
\PDO::ATTR_STRINGIFY_FETCHES => false,
],

This allows Phalcon (i.e. PDO) to convert numeric values to INT