1

Ok guys, I've got this from CakePHP:

array(
    (int) 0 => array(
        'Worker' => array(
            'id' => '1',
            'username' => 'davorlozic',
            'first_name' => 'Davor',
            'last_name' => 'Lozic',
            'active' => true,
            'created' => '2012-05-12 10:39:05',
            'modified' => '2012-05-12 10:39:05'
        )
    ),
    (int) 1 => array(
        'Worker' => array(
            'id' => '2',
            'username' => 'markomarkovic',
            'first_name' => 'Marko',
            'last_name' => 'Markovic',
            'active' => true,
            'created' => '2012-05-12 10:39:20',
            'modified' => '2012-05-12 10:39:20'
        )

So, when I encode it with JSON_ENCODE I get this:

enter image description here

BUT I NEED TO GET THIS: HOW? (this shape, not these data)

{
    "success": true,
    "Workers": [
        {"id": 1, "name": 'Ed',    "email": "ed@sencha.com"},
        {"id": 2, "name": 'Tommy', "email": "tommy@sencha.com"}
    ]
}

Can I do something with the FIRST array? Some shifting or something? Thank you! :)

4

1 に答える 1

0

あなたの現在の問題は、CakePHPExtJSが読み取り要求に異なるデータ構造を使用していることです。おそらく後になって、さらに多くの問題があり、非常にトリッキーになる可能性があることに気付くでしょう。私は多くのCakePHPExtJSプロジェクトで常にこれらの問題に直面してきました。リクエスト タイプとコントローラーごとにカスタムjsonビューを作成しなければならないのも非常に面倒です。

そういうわけで、私はいくつかの大学Banchaと一緒にこれらすべてを自動化することを始めました。banchaproject.orgでサンプルとドキュメントを参照することをお勧めします。

ご不明な点がございましたら、 support@banchaproject.org までお気軽にお問い合わせください。

よろしくローランド

于 2012-09-19T08:11:27.173 に答える