Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs on a symfony2 application

I'm working on a SF2 application that uses a lot of javascript on the front end.

SF2 provides me a good way of building a nice REST app, manage my database with doctrine, use twig for templates and so on, but I would like to use Angularjs.

I know that angularjs an SF2 are 2 different framework with different approach, but I'm wondering what the best way to make this work is.

Is it even worth it?

If yes, what do you think is the cleaner and most efficient solution?

Maybe use php instead of twig for templates to use angularjs curly braces ?

like image 374
Louis Grellet Avatar asked May 31 '12 13:05

Louis Grellet


People also ask

Which application is used for AngularJS?

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.

Can I use AngularJS with PHP?

If you're wondering whether you can use PHP alongside Angular, the answer is yes. But Angular will still need a separate client-server architecture. In general, PHP runs on the server-side while Angular runs on the client-side.

Can I use AngularJS and Angular together?

In a hybrid application you run both versions of Angular at the same time. That means that you need at least one module each from both AngularJS and Angular. You will import UpgradeModule inside the NgModule, and then use it for bootstrapping the AngularJS module.


2 Answers

I think Symfony2 can perfectly work well with AngularJS. Proof is I'm making an API on one side using Symfony, and a web app on the other side with AnglularJS.

Moreover, for some reasons I generate my views in my web app with Twig. I simply embed angular's curly braces in a twig {% verbatim %} {% endverbatim %} statement each time I need to use Angular in my views.

like image 117
Halim Qarroum Avatar answered Oct 19 '22 03:10

Halim Qarroum


As of Twig 1.12 the raw tag was renamed to verbatim:

{% verbatim %}     <ul>     {% for item in seq %}         <li>{{ item }}</li>     {% endfor %}     </ul> {% endverbatim %} 

Everything in-between won't be parsed by the Twig Engine and can be used by AngularJS.

Though I'd recommend changing the AngularJS delimiters. Otherwise it can be hard to distinguish between Twig and AngularJS code when looking at your templates.

like image 31
acme Avatar answered Oct 19 '22 04:10

acme