1

我想从 symfony 社区获得关于如何使用backbone.js创建单页应用程序来实现的观点。
甚至可以通过backbone.js调用symfony中的函数(例如公共函数executeCreate())有人做过吗?
你能给我一些资源吗?提前致谢。

4

3 回答 3

2

I would recommend you to have a look at the FOSRestBundle. Another attempt could be to handle the requests yourself, and return the date from the orm/odm via Serializer

the only thing bothered me so far, was the form handling (used backbone-forms), where I simply not was able to keep my code DRY (had duplicate data for the form+validation in symfony and in the frontend-part).

于 2012-05-04T22:40:48.663 回答
2

为什么不?Symfony 可以轻松地根据骨干客户端应用程序的请求返回 JSON 数据。对于 Symfony2,它可以是这样的:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class MyController extends Controller {
    public function createAction($requestParam1, $requestParam2)
        $response = new Response(json_encode(array(
            'requestParam1' => $requestParam1,
            'requestParam2' => $requestParam2
        )));
        $response->headers->set('Content-Type', 'application/json');

        return $response;
    }
}
于 2012-04-27T16:27:40.477 回答
1

如果你想启动一个新的 Symfony2 + 主干应用程序,我会推荐这个包:

https://github.com/gigo6000/DevtimeBackboneBundle

还有一个演示应用程序可以帮助查看主干.js 和 Symfony2 交互:

https://github.com/gigo6000/DevtimeRafflerBundle

于 2012-12-14T19:04:39.647 回答