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.
- 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
3 Answers
Reset to default 2Why 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