Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[json] howto #8

Open
brikou opened this issue Oct 28, 2011 · 1 comment
Open

[json] howto #8

brikou opened this issue Oct 28, 2011 · 1 comment

Comments

@brikou
Copy link
Contributor

brikou commented Oct 28, 2011

mandango is great (I really mean it ;)) as it only query what is needed but I want to return a json representation of my collection

<?php
    // ...

    $labels = $app['mandango']
        ->getRepository('Model\Label')
        ->createQuery()
        ->all()
    ;

    return new Response(
        json_encode($labels),
        200,
        array('Content-Type' => 'application/json')
    );

$labels only contains ids of my labels, how should i do to hydrate this with all the data... do you have a clue? I havn't found anything in the doc

thx

@brikou
Copy link
Contributor Author

brikou commented Oct 28, 2011

<?php
    //...

    $labels = $app['mandango']
        ->getRepository('Model\Label')
        ->createQuery()
        ->all()
    ;

    array_walk($labels, function(\Model\Label &$label) {
        $label = $label->toArray();
    });

Is this code correct ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant