SlideShare a Scribd company logo
1 of 48
Symfony2 and AngularJS
Antonio Periฤ‡-Maลพar
16.05.2014, PHPday Verona
https://joind.in/talk/view/11290
About me
โ€ข Antonio Periฤ‡-Maลพar,
mag. ing. comp.
โ€ข CEO @ locastic
โ€ข Software developer, Symfony2
โ€ข Sylius Awesome Contributor :)
โ€ข www.locastic.com
โ€ข antonio@locastic.com
โ€ข twitter: @antonioperic
Who we are?
โ€ข locastic (www.locastic.com)
โ€ข Web and mobile development
โ€ข UI/UX design
โ€ข Located in Split, Croatia
Our works?
Symfony2
๏ฌ PHP Framework, server side
๏ฌ MVC, HTTP
๏ฌ Toolbox, methodology
๏ฌ One of the most advanced PHP framework
๏ฌ Strong community
๏ฌ Easy to test it
Symfony2
๏ฌ Bundles
๏ฌ Components
๏ฌ Routing
๏ฌ Templating (Twig)
๏ฌ Forms
๏ฌ etc
AngularJS
๏ฌ Client-side JavaScript framework
๏ฌ Prescriptive, MVC (MVVM)
๏ฌ Makes creating UI easier thought data-binding
๏ฌ Good organizing and architecture
๏ฌ Learning curve, easy to start hard to master
๏ฌ $scope, modules, controllers, providers, services
AngularJS Core
Two-way data binding
JS:
<span id=โ€someIdโ€></span>
document.getElementById('someId').text = 'locastic';
NG
<span>{{someName}}<span>
var someName = 'locastic';
AngularJS Core
<html ng-app>
<head>
<script src=โ€angular.jsโ€></script>
<script src=โ€controller.jsโ€></script>
<head>
<body>
<div ng-controller=โ€HelloControllerโ€>
<p>{{ greeting.text}}, World</p>
</div>
</body>
</html>
// controller.js
function HelloController($scope) {
$scope.gretting = {text: 'Hello'}
}
HTML template
AngularJS Core
๏ฌ Deep Linking
๏ฌ Dependency Injection
๏ฌ Directives
<div class=โ€containerโ€>
<div class=โ€inner>
<ul>
<li>Item
<div class=โ€subitemโ€>Item2</div>
</li>
</ul>
</div>
</div>
<dropdown>
<item>Item 1>
<subitem >Item 2</subitem>
</item>
</dropdown>
+
SPA (Singe Page App)
SPA
๏ฌ Aka SPI (Single Page interface)
๏ฌ desktop apps UX
๏ฌ HTML / JS / CSS / etc in single page load
๏ฌ fast
๏ฌ AJAX and XHR
SPA Arhitecture
Backend (rest api) with Symfony2
Frontend with AngularJs
Separation or combination?
UI == APP
Symfony2 AngularJS
Usage, language Backend, PHP Frontend, Javascript
Dependency Injection Yes Yes
Templating Twig HTML
Form component Yes Yes
Routing component Yes Yes
MVC Yes Yes
Testable Yes Yes
Services Yes Yes
Events Yes Yes
i18n Yes Yes
Dependency management Yes Yes
RESTful ws
Simpler than SOAP & WSDL
Resource-oriented (URI)
Principles:
HTTP methods (idempotent & not)
stateless
directory structure-like URIs
XML or JSON (or XHTML)
Building Rest Api with SF2
There is bundle for everything in Sf2. Right?
So lets use some of them!
Building Rest Api with SF2
What we need?
JMSSerializerBundle
FOSRestBundle
NelmioApiDocBundle
Building Rest API with SF2
JMSSerializerBundle
(de)serialization
via annotations / YAML / XML / PHP
integration with the Doctrine ORM
handling of other complex cases (e.g. circular references)
Building Rest Api with SF2
LocasticBundleTodoBundleEntityTodo:
# exclusion_policy: ALL
exclusion_policy: NONE
properties:
# description:
# expose: true
createdAt:
# expose: true
exclude: true
deadline:
type: DateTime<'d.m.Y. H:i:s'>
# expose: true
done:
# expose: true
serialized_name: status
Building Rest Api with SF2
fos_rest:
disable_csrf_role: ROLE_API
param_fetcher_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json: true
templating_formats:
html: true
format_listener:
rules:
- { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true }
exception:
codes:
'SymfonyComponentRoutingExceptionResourceNotFoundException': 404
'DoctrineORMOptimisticLockException': HTTP_CONFLICT
messages:
'SymfonyComponentRoutingExceptionResourceNotFoundException': true
allowed_methods_listener: true
access_denied_listener:
json: true
body_listener: true
Building Rest Api with SF2
/**
* @ApiDoc(
* resource = true,
* description = "Get stories from users that you follow (newsfeed)",
* section = "Feed",
* output={
* "class" = "LocasticBundleFeedBundleEntityStory"
* },
* statusCodes = {
* 200 = "Returned when successful",
* 400 = "Returned when bad parameters given"
* }
* )
*
* @RestView(
* serializerGroups = {"feed"}
* )
*/
public function getFeedAction()
{
$this->get('locastic_auth.auth.handler')->validateRequest($this->get('request'));
return $this->getDoctrine()->getRepository('locastic.repository.story')->getStories($this->get('request')-
>get('me'));
}
Building Rest Api with SF2
Templating
TWIG <3
Templating
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
{#<link rel="stylesheet" href="{{ asset('css/normalize.css') }}">#}
<link rel="stylesheet" href="{{ asset('css/main.css') }}">
<!-- load bootstrap and fontawesome via CDN -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />
<script src="{{ asset('js/vendor/modernizr-2.6.2.min.js') }}"></script>
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{% block body %}{% endblock %}
{% block javascripts %}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="https://code.angularjs.org/1.2.16/angular-route.min.js"></script>
<script src="{{ asset('js/main.js') }}"></script>
{% endblock %}
</body>
</html>
Templating
Problem:
{{ interpolation tags }} - used both by twig and AngularJS
Templating
{% verbatim %}
{{ message }}
{% endverbatim %}
Templating
var phpDayDemoApp = angular.module('phpDayDemoApp', [],
function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
});
Now we can use
{% block content %}
[[ message ]] {# rendered by AngularJS #}
{% end block %}
Templating
Using assetic for minimize
{% javascripts
"js/angular-modules/mod1.js"
"#s/angular-modules/mod2.js"
"@AngBundle/Resources/public/js/controller/*.js"
output="compiled/js/app.js"
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Templating
Using assetic for minimize
Since Angular infers the controller's dependencies from the names of
arguments to the controller's constructor function, if you were to minify the
JavaScript code for PhoneListCtrl controller, all of its function arguments
would be minified as well, and the dependency injector would not be able
to identify services correctly.
Use an inline annotation where, instead of just providing the function, you
provide an array. This array contains a list of the service names, followed by
the function itself.
function PhoneListCtrl($scope, $http) {...}
phonecatApp.controller('phpDayCtrl', ['$scope', '$http', PhoneListCtrl]);
Managing routes
Client side:
ngRoute
independent since Angular 1.1.6
hashbang #! & HTML5 mode
<base href="/">
$locationProvider
.html5Mode(true)
.hashPrefix('!');
Managing routes
http://localhost/todos
http://localhost/#todos
Resolving conflicts
Fallback, managing 404
Managing routes
Client side:
// module configuration...$routeProvider.when('/todos/show/:id', {
templateUrl : 'todo/show',
controller : 'todoController'
})
// receive paramssfugDemoApp.controller('todoController', function($scope, $http, $routeParams){
$scope.todo = {};
$http
.get('/api/todo/show/' + $routeParams.id)
.success(function(data){
$scope.todo = data['todo'];
});
});
Managing routes
Server side:
locastic_rest_todo_getall:
pattern: /api/get-all
defaults:
_controller: LocasticRestBundle:Todo:getAll
locastic_rest_todo_create:
pattern: /api/create
defaults:
_controller: LocasticRestBundle:Todo:create
locastic_rest_todo_show:
pattern: /api/show/{id}
defaults:
_controller: LocasticRestBundle:Todo:show
Translations
AngularJS has its own translation system
I18N/L10N . But it might be interesting to monitor
and centralize translations from your backend
Symfony.
Forms
Symfony Forms <3
We don't want to throw them away
Build custom directive
Forms
sfugDemoApp.directive('ngToDoForm', function() {
return {
restrict: 'E',
template: '<div class="todoForm">Form will be!</div>'
}
});
'A' - <span ng-sparkline></span>
'E' - <ng-sparkline></ng-sparkline>
'C' - <span class="ng-sparkline"></span>
'M' - <!-- directive: ng-sparkline โ†’
Usage of directive in HTML:
<ng-to-do-form></ng-to-do-form>
Forms
sfugDemoApp.directive('ngToDoForm', function() {
return {
restrict: 'E',
templateUrl: '/api/form/show.html'
}
});
Forms
sfugDemoApp.directive('ngToDoForm', function() {
return {
restrict: 'E',
templateUrl: '/api/form/show.html'
}
});
locastic_show_form:
pattern: /form/show.html
defaults:
_controller: LocasticWebBundle:Default:renderForm
public function renderFormAction()
{
$form = $this->createForm(new TodoType());
return $this->render('LocasticWebBundle::render_form.html.twig', array(
'form' => $form->createView()
));
}
Forms
Suprise!!!
Form
Template behind directive
<form class="form-inline" role="form" style="margin-bottom: 30px;">
Create new todo:
<div class="form-group">
{{ form_label(form.description) }}
{{ form_widget(form.description, {'attr': {'ng-model': 'newTodo.description', 'placeholder':
'description', 'class': 'form-control'}}) }}
</div>
<div class="form-group">
<label class="sr-only" for="deadline">Deadline</label>
<input type="text" class="form-control" id="deadline" placeholder="deadline (angular-ui)" ng-
model="newTodo.deadline">
</div>
<input type="button" class="btn btn-default" ng-click="addNew()" value="add"/>
</form>
Testing
Symfony and AngularJS are designed to test. So write test
Behat
PHPUnit
PHPSpec
Jasmine
โ€ฆ
Or whatever you want just write tests
Summary
The cleanest way is to separate backend and frontend. But there is some
advantages to use both together.
Twig + HTML works well.
Assetic Bundle is very useful to minify bunches of Javascript files used by
AngularJs
Translation in the template. the data in the API payload does not need
translation in most cases. Using Symfony I18N support for the template
makes perfect sense.
Loading of Option lists. Say you have a country list with 200+ options. You
can build an API to populate a dynamic dropdown in angularjs, but as these
And remember
Keep controllers small and stupid, master Dependency
injection, delegate to services and events.
Thank you!
QA
Please rate my talk
https://joind.in/talk/view/11290
follow me on twitter: @antonioperic

More Related Content

What's hot

Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
taggg
ย 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
gerbille
ย 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
Ignacio Martรญn
ย 

What's hot (20)

Ionicแ„‹แ…ณแ„…แ…ฉ แ„†แ…ฉแ„‡แ…กแ„‹แ…ตแ†ฏแ„‹แ…ขแ†ธ แ„†แ…กแ†ซแ„ƒแ…ณแ†ฏแ„€แ…ต #4
Ionicแ„‹แ…ณแ„…แ…ฉ แ„†แ…ฉแ„‡แ…กแ„‹แ…ตแ†ฏแ„‹แ…ขแ†ธ แ„†แ…กแ†ซแ„ƒแ…ณแ†ฏแ„€แ…ต #4Ionicแ„‹แ…ณแ„…แ…ฉ แ„†แ…ฉแ„‡แ…กแ„‹แ…ตแ†ฏแ„‹แ…ขแ†ธ แ„†แ…กแ†ซแ„ƒแ…ณแ†ฏแ„€แ…ต #4
Ionicแ„‹แ…ณแ„…แ…ฉ แ„†แ…ฉแ„‡แ…กแ„‹แ…ตแ†ฏแ„‹แ…ขแ†ธ แ„†แ…กแ†ซแ„ƒแ…ณแ†ฏแ„€แ…ต #4
ย 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
ย 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.
ย 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
ย 
Mojolicious
MojoliciousMojolicious
Mojolicious
ย 
PHP MVC
PHP MVCPHP MVC
PHP MVC
ย 
Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2
ย 
#31.์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ & ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค (Spring Framework, MyBatis)_์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ ๊ฐ•์ขŒ, ์žฌ์ง์žํ™˜๊ธ‰๊ต์œก,์‹ค์—…์ž๊ตญ๋น„์ง€์›...
#31.์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ & ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค (Spring Framework, MyBatis)_์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ ๊ฐ•์ขŒ, ์žฌ์ง์žํ™˜๊ธ‰๊ต์œก,์‹ค์—…์ž๊ตญ๋น„์ง€์›...#31.์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ & ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค (Spring Framework, MyBatis)_์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ ๊ฐ•์ขŒ, ์žฌ์ง์žํ™˜๊ธ‰๊ต์œก,์‹ค์—…์ž๊ตญ๋น„์ง€์›...
#31.์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ & ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค (Spring Framework, MyBatis)_์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ ๊ฐ•์ขŒ, ์žฌ์ง์žํ™˜๊ธ‰๊ต์œก,์‹ค์—…์ž๊ตญ๋น„์ง€์›...
ย 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
ย 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
ย 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHP
ย 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
ย 
Laravel แ„…แ…ฉ แ„‡แ…ขแ„‹แ…ฎแ„‚แ…ณแ†ซ แ„‰แ…ฅแ„‡แ…ฅแ„‰แ…กแ„‹แ…ตแ„ƒแ…ณ #5
Laravel แ„…แ…ฉ แ„‡แ…ขแ„‹แ…ฎแ„‚แ…ณแ†ซ แ„‰แ…ฅแ„‡แ…ฅแ„‰แ…กแ„‹แ…ตแ„ƒแ…ณ #5Laravel แ„…แ…ฉ แ„‡แ…ขแ„‹แ…ฎแ„‚แ…ณแ†ซ แ„‰แ…ฅแ„‡แ…ฅแ„‰แ…กแ„‹แ…ตแ„ƒแ…ณ #5
Laravel แ„…แ…ฉ แ„‡แ…ขแ„‹แ…ฎแ„‚แ…ณแ†ซ แ„‰แ…ฅแ„‡แ…ฅแ„‰แ…กแ„‹แ…ตแ„ƒแ…ณ #5
ย 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
ย 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
ย 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
ย 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
ย 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
ย 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
ย 
Symfony 2
Symfony 2Symfony 2
Symfony 2
ย 

Viewers also liked

Symfony and Angularjs
Symfony and AngularjsSymfony and Angularjs
Symfony and Angularjs
Iwan van Staveren
ย 
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
Abdelkader Rhouati
ย 
Starting with Symfony2
Starting with Symfony2Starting with Symfony2
Starting with Symfony2
Kevin Bond
ย 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
Marian Marinov
ย 

Viewers also liked (20)

Symfony + AngularJS | Mladen Plavsic @DaFED26
Symfony + AngularJS | Mladen Plavsic @DaFED26Symfony + AngularJS | Mladen Plavsic @DaFED26
Symfony + AngularJS | Mladen Plavsic @DaFED26
ย 
Symfony and Angularjs
Symfony and AngularjsSymfony and Angularjs
Symfony and Angularjs
ย 
Desarrollo Web รgil con Symfony, Bootstrap y Angular
Desarrollo Web รgil con Symfony, Bootstrap y AngularDesarrollo Web รgil con Symfony, Bootstrap y Angular
Desarrollo Web รgil con Symfony, Bootstrap y Angular
ย 
Symfony with angular.pptx
Symfony with angular.pptxSymfony with angular.pptx
Symfony with angular.pptx
ย 
deSymfony 2013 - Creando aplicaciones web desde otro aฬngulo con Symfony y A...
deSymfony 2013 -  Creando aplicaciones web desde otro aฬngulo con Symfony y A...deSymfony 2013 -  Creando aplicaciones web desde otro aฬngulo con Symfony y A...
deSymfony 2013 - Creando aplicaciones web desde otro aฬngulo con Symfony y A...
ย 
A Practical Introduction to Symfony2
A Practical Introduction to Symfony2A Practical Introduction to Symfony2
A Practical Introduction to Symfony2
ย 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulaires
ย 
REST APIs in the context of single-page applications
REST APIs in the context of single-page applicationsREST APIs in the context of single-page applications
REST APIs in the context of single-page applications
ย 
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
ุจุฑู†ุงู…ุฌ ุฌู…ุนูŠุฉ ุจุณู…ุฉ ุฃู…ู„ ุจูˆุฌุฏุฉ ู„ุณู†ุฉ 2013
ย 
Symfony2 e Elasticsearch com FosElasticaBundle
Symfony2 e Elasticsearch com FosElasticaBundleSymfony2 e Elasticsearch com FosElasticaBundle
Symfony2 e Elasticsearch com FosElasticaBundle
ย 
Maintainable + Extensible = Clean ... yes, Code!
Maintainable + Extensible = Clean ... yes, Code! Maintainable + Extensible = Clean ... yes, Code!
Maintainable + Extensible = Clean ... yes, Code!
ย 
Starting with Symfony2
Starting with Symfony2Starting with Symfony2
Starting with Symfony2
ย 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
ย 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
ย 
PPT on Angular 2 Development Tutorial
PPT on Angular 2 Development TutorialPPT on Angular 2 Development Tutorial
PPT on Angular 2 Development Tutorial
ย 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
ย 
LVIV IT Arena - SmartHome using low cost components
LVIV IT Arena - SmartHome using low cost componentsLVIV IT Arena - SmartHome using low cost components
LVIV IT Arena - SmartHome using low cost components
ย 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
ย 
Java9 moduulit jigsaw
Java9 moduulit jigsawJava9 moduulit jigsaw
Java9 moduulit jigsaw
ย 
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
ย 

Similar to Symfony2 and AngularJS

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
ย 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
ย 
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
Sรฉbastien Levert
ย 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
ย 

Similar to Symfony2 and AngularJS (20)

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
ย 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
ย 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
ย 
Knolx session
Knolx sessionKnolx session
Knolx session
ย 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
ย 
Next Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooNext Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring Roo
ย 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
ย 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
ย 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
ย 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
ย 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
ย 
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
ย 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
ย 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
ย 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
ย 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ใƒฉใ‚คใƒ–ใ‚ณใƒผใƒ‡ใ‚ฃใƒณใ‚ฐ
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ใƒฉใ‚คใƒ–ใ‚ณใƒผใƒ‡ใ‚ฃใƒณใ‚ฐXitrum Web Framework Live Coding Demos / Xitrum Web Framework ใƒฉใ‚คใƒ–ใ‚ณใƒผใƒ‡ใ‚ฃใƒณใ‚ฐ
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ใƒฉใ‚คใƒ–ใ‚ณใƒผใƒ‡ใ‚ฃใƒณใ‚ฐ
ย 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
ย 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
ย 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
ย 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
ย 

More from Antonio Peric-Mazar

More from Antonio Peric-Mazar (20)

You call yourself a Senior Developer?
You call yourself a Senior Developer?You call yourself a Senior Developer?
You call yourself a Senior Developer?
ย 
Using API Platform to build ticketing system #symfonycon
Using API Platform to build ticketing system #symfonyconUsing API Platform to build ticketing system #symfonycon
Using API Platform to build ticketing system #symfonycon
ย 
Using API platform to build ticketing system (translations, time zones, ...) ...
Using API platform to build ticketing system (translations, time zones, ...) ...Using API platform to build ticketing system (translations, time zones, ...) ...
Using API platform to build ticketing system (translations, time zones, ...) ...
ย 
Are you failing at being agile? #digitallabin
Are you failing at being agile? #digitallabinAre you failing at being agile? #digitallabin
Are you failing at being agile? #digitallabin
ย 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19
ย 
A year with progressive web apps! #webinale
A year with progressive web apps! #webinaleA year with progressive web apps! #webinale
A year with progressive web apps! #webinale
ย 
The UI is the THE application #dpc19
The UI is the THE application #dpc19The UI is the THE application #dpc19
The UI is the THE application #dpc19
ย 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrb
ย 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
ย 
A year with progressive web apps! #DevConMU
A year with progressive web apps! #DevConMUA year with progressive web apps! #DevConMU
A year with progressive web apps! #DevConMU
ย 
Service workers are your best friends
Service workers are your best friendsService workers are your best friends
Service workers are your best friends
ย 
Progressive Web Apps are here!
Progressive Web Apps are here!Progressive Web Apps are here!
Progressive Web Apps are here!
ย 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
ย 
Symfony4 - A new way of developing web applications
Symfony4 - A new way of developing web applicationsSymfony4 - A new way of developing web applications
Symfony4 - A new way of developing web applications
ย 
Build your business on top of Open Source
Build your business on top of Open SourceBuild your business on top of Open Source
Build your business on top of Open Source
ย 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
ย 
Lessons learned while developing with Sylius
Lessons learned while developing with SyliusLessons learned while developing with Sylius
Lessons learned while developing with Sylius
ย 
Drupal8 for Symfony developers - Dutch PHP
Drupal8 for Symfony developers - Dutch PHPDrupal8 for Symfony developers - Dutch PHP
Drupal8 for Symfony developers - Dutch PHP
ย 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
ย 
Drupal8 for Symfony Developers
Drupal8 for Symfony DevelopersDrupal8 for Symfony Developers
Drupal8 for Symfony Developers
ย 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
bodapatigopi8531
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
ย 

Recently uploaded (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 

Symfony2 and AngularJS

  • 1. Symfony2 and AngularJS Antonio Periฤ‡-Maลพar 16.05.2014, PHPday Verona https://joind.in/talk/view/11290
  • 2. About me โ€ข Antonio Periฤ‡-Maลพar, mag. ing. comp. โ€ข CEO @ locastic โ€ข Software developer, Symfony2 โ€ข Sylius Awesome Contributor :) โ€ข www.locastic.com โ€ข antonio@locastic.com โ€ข twitter: @antonioperic
  • 3. Who we are? โ€ข locastic (www.locastic.com) โ€ข Web and mobile development โ€ข UI/UX design โ€ข Located in Split, Croatia
  • 5.
  • 6. Symfony2 ๏ฌ PHP Framework, server side ๏ฌ MVC, HTTP ๏ฌ Toolbox, methodology ๏ฌ One of the most advanced PHP framework ๏ฌ Strong community ๏ฌ Easy to test it
  • 7. Symfony2 ๏ฌ Bundles ๏ฌ Components ๏ฌ Routing ๏ฌ Templating (Twig) ๏ฌ Forms ๏ฌ etc
  • 8. AngularJS ๏ฌ Client-side JavaScript framework ๏ฌ Prescriptive, MVC (MVVM) ๏ฌ Makes creating UI easier thought data-binding ๏ฌ Good organizing and architecture ๏ฌ Learning curve, easy to start hard to master ๏ฌ $scope, modules, controllers, providers, services
  • 9. AngularJS Core Two-way data binding JS: <span id=โ€someIdโ€></span> document.getElementById('someId').text = 'locastic'; NG <span>{{someName}}<span> var someName = 'locastic';
  • 10. AngularJS Core <html ng-app> <head> <script src=โ€angular.jsโ€></script> <script src=โ€controller.jsโ€></script> <head> <body> <div ng-controller=โ€HelloControllerโ€> <p>{{ greeting.text}}, World</p> </div> </body> </html> // controller.js function HelloController($scope) { $scope.gretting = {text: 'Hello'} } HTML template
  • 11. AngularJS Core ๏ฌ Deep Linking ๏ฌ Dependency Injection ๏ฌ Directives <div class=โ€containerโ€> <div class=โ€inner> <ul> <li>Item <div class=โ€subitemโ€>Item2</div> </li> </ul> </div> </div> <dropdown> <item>Item 1> <subitem >Item 2</subitem> </item> </dropdown>
  • 13. SPA ๏ฌ Aka SPI (Single Page interface) ๏ฌ desktop apps UX ๏ฌ HTML / JS / CSS / etc in single page load ๏ฌ fast ๏ฌ AJAX and XHR
  • 14.
  • 15. SPA Arhitecture Backend (rest api) with Symfony2 Frontend with AngularJs Separation or combination?
  • 17. Symfony2 AngularJS Usage, language Backend, PHP Frontend, Javascript Dependency Injection Yes Yes Templating Twig HTML Form component Yes Yes Routing component Yes Yes MVC Yes Yes Testable Yes Yes Services Yes Yes Events Yes Yes i18n Yes Yes Dependency management Yes Yes
  • 18. RESTful ws Simpler than SOAP & WSDL Resource-oriented (URI) Principles: HTTP methods (idempotent & not) stateless directory structure-like URIs XML or JSON (or XHTML)
  • 19. Building Rest Api with SF2 There is bundle for everything in Sf2. Right? So lets use some of them!
  • 20. Building Rest Api with SF2 What we need? JMSSerializerBundle FOSRestBundle NelmioApiDocBundle
  • 21. Building Rest API with SF2 JMSSerializerBundle (de)serialization via annotations / YAML / XML / PHP integration with the Doctrine ORM handling of other complex cases (e.g. circular references)
  • 22. Building Rest Api with SF2 LocasticBundleTodoBundleEntityTodo: # exclusion_policy: ALL exclusion_policy: NONE properties: # description: # expose: true createdAt: # expose: true exclude: true deadline: type: DateTime<'d.m.Y. H:i:s'> # expose: true done: # expose: true serialized_name: status
  • 23. Building Rest Api with SF2 fos_rest: disable_csrf_role: ROLE_API param_fetcher_listener: true view: view_response_listener: 'force' formats: xml: true json: true templating_formats: html: true format_listener: rules: - { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true } exception: codes: 'SymfonyComponentRoutingExceptionResourceNotFoundException': 404 'DoctrineORMOptimisticLockException': HTTP_CONFLICT messages: 'SymfonyComponentRoutingExceptionResourceNotFoundException': true allowed_methods_listener: true access_denied_listener: json: true body_listener: true
  • 24. Building Rest Api with SF2 /** * @ApiDoc( * resource = true, * description = "Get stories from users that you follow (newsfeed)", * section = "Feed", * output={ * "class" = "LocasticBundleFeedBundleEntityStory" * }, * statusCodes = { * 200 = "Returned when successful", * 400 = "Returned when bad parameters given" * } * ) * * @RestView( * serializerGroups = {"feed"} * ) */ public function getFeedAction() { $this->get('locastic_auth.auth.handler')->validateRequest($this->get('request')); return $this->getDoctrine()->getRepository('locastic.repository.story')->getStories($this->get('request')- >get('me')); }
  • 25. Building Rest Api with SF2
  • 27. Templating <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>{% block title %}Welcome!{% endblock %}</title> {% block stylesheets %} <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> {#<link rel="stylesheet" href="{{ asset('css/normalize.css') }}">#} <link rel="stylesheet" href="{{ asset('css/main.css') }}"> <!-- load bootstrap and fontawesome via CDN --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" /> <script src="{{ asset('js/vendor/modernizr-2.6.2.min.js') }}"></script> {% endblock %} <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" /> </head> <body> {% block body %}{% endblock %} {% block javascripts %} <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script> <script src="https://code.angularjs.org/1.2.16/angular-route.min.js"></script> <script src="{{ asset('js/main.js') }}"></script> {% endblock %} </body> </html>
  • 28. Templating Problem: {{ interpolation tags }} - used both by twig and AngularJS
  • 29. Templating {% verbatim %} {{ message }} {% endverbatim %}
  • 30. Templating var phpDayDemoApp = angular.module('phpDayDemoApp', [], function($interpolateProvider) { $interpolateProvider.startSymbol('[['); $interpolateProvider.endSymbol(']]'); }); Now we can use {% block content %} [[ message ]] {# rendered by AngularJS #} {% end block %}
  • 31. Templating Using assetic for minimize {% javascripts "js/angular-modules/mod1.js" "#s/angular-modules/mod2.js" "@AngBundle/Resources/public/js/controller/*.js" output="compiled/js/app.js" %} <script type="text/javascript" src="{{ asset_url }}"></script> {% endjavascripts %}
  • 32. Templating Using assetic for minimize Since Angular infers the controller's dependencies from the names of arguments to the controller's constructor function, if you were to minify the JavaScript code for PhoneListCtrl controller, all of its function arguments would be minified as well, and the dependency injector would not be able to identify services correctly. Use an inline annotation where, instead of just providing the function, you provide an array. This array contains a list of the service names, followed by the function itself. function PhoneListCtrl($scope, $http) {...} phonecatApp.controller('phpDayCtrl', ['$scope', '$http', PhoneListCtrl]);
  • 33. Managing routes Client side: ngRoute independent since Angular 1.1.6 hashbang #! & HTML5 mode <base href="/"> $locationProvider .html5Mode(true) .hashPrefix('!');
  • 35. Managing routes Client side: // module configuration...$routeProvider.when('/todos/show/:id', { templateUrl : 'todo/show', controller : 'todoController' }) // receive paramssfugDemoApp.controller('todoController', function($scope, $http, $routeParams){ $scope.todo = {}; $http .get('/api/todo/show/' + $routeParams.id) .success(function(data){ $scope.todo = data['todo']; }); });
  • 36. Managing routes Server side: locastic_rest_todo_getall: pattern: /api/get-all defaults: _controller: LocasticRestBundle:Todo:getAll locastic_rest_todo_create: pattern: /api/create defaults: _controller: LocasticRestBundle:Todo:create locastic_rest_todo_show: pattern: /api/show/{id} defaults: _controller: LocasticRestBundle:Todo:show
  • 37. Translations AngularJS has its own translation system I18N/L10N . But it might be interesting to monitor and centralize translations from your backend Symfony.
  • 38. Forms Symfony Forms <3 We don't want to throw them away Build custom directive
  • 39. Forms sfugDemoApp.directive('ngToDoForm', function() { return { restrict: 'E', template: '<div class="todoForm">Form will be!</div>' } }); 'A' - <span ng-sparkline></span> 'E' - <ng-sparkline></ng-sparkline> 'C' - <span class="ng-sparkline"></span> 'M' - <!-- directive: ng-sparkline โ†’ Usage of directive in HTML: <ng-to-do-form></ng-to-do-form>
  • 40. Forms sfugDemoApp.directive('ngToDoForm', function() { return { restrict: 'E', templateUrl: '/api/form/show.html' } });
  • 41. Forms sfugDemoApp.directive('ngToDoForm', function() { return { restrict: 'E', templateUrl: '/api/form/show.html' } }); locastic_show_form: pattern: /form/show.html defaults: _controller: LocasticWebBundle:Default:renderForm public function renderFormAction() { $form = $this->createForm(new TodoType()); return $this->render('LocasticWebBundle::render_form.html.twig', array( 'form' => $form->createView() )); }
  • 43. Form Template behind directive <form class="form-inline" role="form" style="margin-bottom: 30px;"> Create new todo: <div class="form-group"> {{ form_label(form.description) }} {{ form_widget(form.description, {'attr': {'ng-model': 'newTodo.description', 'placeholder': 'description', 'class': 'form-control'}}) }} </div> <div class="form-group"> <label class="sr-only" for="deadline">Deadline</label> <input type="text" class="form-control" id="deadline" placeholder="deadline (angular-ui)" ng- model="newTodo.deadline"> </div> <input type="button" class="btn btn-default" ng-click="addNew()" value="add"/> </form>
  • 44. Testing Symfony and AngularJS are designed to test. So write test Behat PHPUnit PHPSpec Jasmine โ€ฆ Or whatever you want just write tests
  • 45. Summary The cleanest way is to separate backend and frontend. But there is some advantages to use both together. Twig + HTML works well. Assetic Bundle is very useful to minify bunches of Javascript files used by AngularJs Translation in the template. the data in the API payload does not need translation in most cases. Using Symfony I18N support for the template makes perfect sense. Loading of Option lists. Say you have a country list with 200+ options. You can build an API to populate a dynamic dropdown in angularjs, but as these
  • 46. And remember Keep controllers small and stupid, master Dependency injection, delegate to services and events.
  • 48. QA Please rate my talk https://joind.in/talk/view/11290 follow me on twitter: @antonioperic