1

My quick question is, should I begin using a javascript framework at the same time that I build my project with symfony or can I do it later without major troubles?

I have a small project of one page app written in flat PHP and jquery. Now I'm trying to port my project to symfony and I would like to use a javascript framework too. After one month of learning symfony I think that I begin to understand how it works, but I have a mess in my head with all those javascript frameworks available. I think that is better to focus all my attention to symfony and once I fully understand how it works try to use a framework for javascript.

But I'm afraid of using a javascript framework implies changing a lot of my symfony code and twig templates. Right now, I'm using repositories and services to get data for the controller and then return it to javascript in JSON format. I understand that this shouldn't change (at least the part where I get the data) but I read some articles of people using bundles like FOSRestBundle and JMSSerializerBundle to return the data and using templates from javascript like mustache to render it, so I'm a little confused and I don't know if this will be a big change or if this is needed between symfony and javacript framework.

EDIT:

When I say javascript framework I'm talking about a combination of backbone + chaplin or marionette, for example. I think that jquery is just a library, not a framework, and backbone needs jquery to work.

3 Answers 3

1

All websites are completed by JS now, to be more user friendly and interactive, so yes of course you can use JQuery right now, from the beginning of your project because if you don't you will lose time by refactoring your actions to works with JS interactions and callback !

In addition, it will learn you how to manage JS in a Symfony project. You are free to use a vendor bundle or not to return JSON. You can simply do like that :

// action :

public function myAjaxAction()
{
    // do something

    return new Response(
        json_encode(
            array(
                'success' => 0,
                'error' => 'No image found.
            )
    ));
}

And to finish, some documentation of Symfony2 use JQuery, like this : http://symfony.com/doc/current/cookbook/form/form_collections.html

So yes you can use JQuery now !

1
  • Thanks for the answer, I'm sorry if I didn't explain it correctly. I know that I can use Jquery. I used Jquery with flat PHP and I'm using right now with symfony. My doubt is If I should use a framework like backbone + chaplin from the beginnig or I can rewrite my javascript in the future without changing my symfony code. I edited my question to make it clear. Commented Aug 29, 2013 at 11:23
0

I'm not getting you. If you want to convert flat JS into JS framework in the future, why don't you use that from now on? From my experience, it's not easy work to convert your js(jquery way) into REAL Backbone way. Because you need to reconstruct all of your js code, even symfony code.

Though it's harder to use two new kind of technologies for you, I think you should try it.

3
  • Ok, that's the point! I was afraid about reconstruct my symfony code. I don't care about JS because I have already coded it. I have a lot of things to learn with symfony and I wanted to focus only in symfony, but if I have to rewrite my symfony code to use backbone I will start learning it right now! Can you explain me a little how backbone will affect my symfony code? Commented Aug 29, 2013 at 17:06
  • As you know, the better way to use Backbone is REST. Maybe You need to make all of routers follow the way. Maybe you need to change the response data and error status code/message. Maybe you need to modify many PHP templates and take them out from controllers. Unless you understand Backbone very much, you will always run many problems that you can't predict on the way of converting traditional js way to backbone way. Commented Aug 29, 2013 at 20:50
  • Thank you, that's just what I wanted to know. I have started with these simple but clear tutorials http://backbonetutorials.com Commented Aug 29, 2013 at 22:45
0

Yes, you can use it very easily. Symfony is mostly for backend. You can put in Backbonejs or Angularjs for front-end stuff.

3
  • Ok, thank you so much for clarification. I will build my project with symfony and jquery only. In the future, when I fully understand how symfony works I will learn backbone or angular and I will port all my javascript code to a framework. Commented Aug 29, 2013 at 13:12
  • 1
    Then I'd recommend Backbone over angularjs, because Angularjs (may) require you to rework your backend significantly Commented Aug 29, 2013 at 13:22
  • As I have said to @pengjunyong I was afraid of rework my backend. I don't want to do that! So I must learn backbone at the same time than symfony, that's why I wrote my question, I wanted someone to confirm that point. If you can explain me a little how backbone will affect my backend I will mark my question as answered. Commented Aug 29, 2013 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.