php - Using Symfony with Backbone.js - Stack Overflow

I wanted to get views from the symfony munity about how one would achieve using backbone.js to create a

I wanted to get views from the symfony munity about how one would achieve using backbone.js to create a one paged application.
Is it even possible to call the functions in symfony (e.g public function executeCreate()) through backbone.js) has anyone done it?
Can you give me some resources? thanks in advance.

I wanted to get views from the symfony munity about how one would achieve using backbone.js to create a one paged application.
Is it even possible to call the functions in symfony (e.g public function executeCreate()) through backbone.js) has anyone done it?
Can you give me some resources? thanks in advance.

Share Improve this question edited Sep 20, 2012 at 19:23 j0k 22.8k28 gold badges81 silver badges90 bronze badges asked Apr 27, 2012 at 16:16 underscore666underscore666 1,7395 gold badges24 silver badges38 bronze badges 1
  • Of course you cannot directly access a php method through javascript (client vs. server). You would have to provide a API of some kind (REST anyone?) which the js could use to access and post data. – Sgoettschkes Commented Apr 27, 2012 at 21:41
Add a ment  | 

3 Answers 3

Reset to default 2

Why not? Symfony easily can return JSON data on request by backbone clientside app. For Symfony2 it can be like this:

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;
    }
}

I would remend 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).

If you want to start a new Symfony2 + backbone app, I would remend this bundle:

https://github./gigo6000/DevtimeBackboneBundle

There's also a demo app that can be helpful to see the backbone.js and Symfony2 interaction:

https://github./gigo6000/DevtimeRafflerBundle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745616603a4636274.html

相关推荐

  • php - Using Symfony with Backbone.js - Stack Overflow

    I wanted to get views from the symfony munity about how one would achieve using backbone.js to create a

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信