Search code examples
phpangularjssymfonyscaffolding

angularJS within Symfony2?


I have very basic Symfony2 application. I would like including AngularJS within it.

  1. Where should I put my Angular resources?
  2. How to include them?
  3. How to communicate between Angular and Symfony

I see that official documentation says that I should split frontend and backend so that there cannot be any conflict.

Any scaffolding examples?


Solution

  • As Angular resources must be directly accessible from the web browser in their entirety, you should put all these files within the [Symfony app root]/web/ directory. When an HTTP request requests a file located there, it will be served without interacting with the rest of the framework.

    Optionally (and preferably) these pages can be pointed to with the routing component to make pretty URLs.

    I agree with user3142446's answer about creating a REST API and allowing Angular to perform all of the heavy work. There's a well documented bundle for creating REST API's with Symfony called FOSRestBundle to get you started. By using this strategy you can utilize anything done in Symfony the same way you use external APIs.