Developer Data Modeling Mistakes: From Postgres to NoSQL
Creating Mobile Apps With PHP & Symfony2
1. Creating Mobile Apps with
PHP & Symfony2
Pablo Godel @pgodel
http://joind.in/8675
Symfony Live, Portland, May 22 2013
Thursday, May 23, 13
2. ⁃ Born in Argentina, living in the US since 1999
⁃ PHP & Symfony developer
⁃ Founder of the original PHP mailing list in spanish
⁃ Master of the parrilla
⁃ Co-founder of ServerGrove
Who am I?!
Thursday, May 23, 13
5. ⁃ Founded ServerGrove Networks in 2005
⁃ Provider of web hosting specialized in PHP,
Symfony, ZendFramework, MongoDB and others
⁃ Servers in USA and Europe!
Who am I?!
Thursday, May 23, 13
6. ⁃ Very active open source supporter through code
contributions and usergroups/conference sponsoring
Community is our Teacher
Thursday, May 23, 13
8. •More & more people have access to Internet through
mobile devices
Mobile Apps - Why
Thursday, May 23, 13
9. •More & more people have access to Internet through
mobile devices
•Devices are more powerful & versatile
Mobile Apps - Why
Thursday, May 23, 13
10. •More & more people have access to Internet through
mobile devices
•Devices are more powerful & versatile
•Internet access is faster and more reliable
Mobile Apps - Why
Thursday, May 23, 13
11. •More & more people have access to Internet through
mobile devices
•Devices are more powerful & versatile
•Internet access is faster and more reliable
•Users demand services and applications on the go at all
times
Mobile Apps - Why
Thursday, May 23, 13
12. •More & more people have access to Internet through
mobile devices
•Devices are more powerful & versatile
•Internet access is faster and more reliable
•Users demand services and applications on the go at all
times
•Don’t give advantages in an ultra-competitive market
Mobile Apps - Why
Thursday, May 23, 13
14. •Estimated 6.5 billion mobile subscriptions globally (over
90%)
Mobile Apps - Why
Thursday, May 23, 13
15. •Estimated 6.5 billion mobile subscriptions globally (over
90%)
•1.7 billion mobile phones sold in 2012
Mobile Apps - Why
Thursday, May 23, 13
16. •Estimated 6.5 billion mobile subscriptions globally (over
90%)
•1.7 billion mobile phones sold in 2012
•1 billion users in China alone
Mobile Apps - Why
Thursday, May 23, 13
17. •Estimated 6.5 billion mobile subscriptions globally (over
90%)
•1.7 billion mobile phones sold in 2012
•1 billion users in China alone
•321M subscriptions in the US (over 100%)
Mobile Apps - Why
Thursday, May 23, 13
18. •Estimated 6.5 billion mobile subscriptions globally (over
90%)
•1.7 billion mobile phones sold in 2012
•1 billion users in China alone
•321M subscriptions in the US (over 100%)
•Devices range from phone and tablets to door locks,
thermostats, TVs, Cars, etc.
Mobile Apps - Why
Thursday, May 23, 13
19. How did we get here?
Mobile Apps - Why
Thursday, May 23, 13
20. Let’s see some history...
Mobile Apps - History
Thursday, May 23, 13
21. First commercial cellular network launched in
Japan )1G - first generation(
1979
Mobile Apps - History
Thursday, May 23, 13
22. The “mobile” telephone
Motorola DynaTAC -
aka “The Boot”
cost: US$ 3995
weight:793g / 28 ounces
1983 Motorola DynaTAC
Mobile Apps - History
Thursday, May 23, 13
23. Common Standard to connect networks and
apps
•WAP client
•Server sends WML (XML)
WAP - Wireless Application Protocol
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<wml>
<card id="main" title="First Card">
<p mode="wrap">This is a sample WML
page.</p>
</card>
</wml>
1997
Mobile Apps - History
Thursday, May 23, 13
40. Mobile Apps - Symfony
Definition by Fabien Potencier:
⁃ Symfony2 is a reusable set of standalone,
decoupled, and cohesive PHP components
that solve common web development
problems.
⁃ Based on these components, Symfony2 is
also a full-stack web framework.
http://fabien.potencier.org/article/49/what-is-symfony2
Thursday, May 23, 13
45. •Provides solid base to build good HTTP &
RESTful APIs
Mobile Apps - Symfony
Thursday, May 23, 13
46. •Provides solid base to build good HTTP &
RESTful APIs
•Twig makes it easy to build templates for
mobile devices
Mobile Apps - Symfony
Thursday, May 23, 13
47. •Provides solid base to build good HTTP &
RESTful APIs
•Twig makes it easy to build templates for
mobile devices
•Re-use code for different devices thanks to
templates, controllers and routing
Mobile Apps - Symfony
Thursday, May 23, 13
48. •Provides solid base to build good HTTP &
RESTful APIs
•Twig makes it easy to build templates for
mobile devices
•Re-use code for different devices thanks to
templates, controllers and routing
•Bundles + Composer = Endless possibilities!
Mobile Apps - Symfony
Thursday, May 23, 13
51. Frameworks HTML / Javascript
• iui
http://code.google.com/p/iui/ (one of the first ones)
• JQuery Mobile
http://jquerymobile.com/ (Open source)
• JQTouch
http://jqtouch.com/ (Open source)
• DHTMLX Touch
http://dhtmlx.com/touch/ (Open source)
• The M Project
http://www.the-m-project.org/ (Open source)
• Sensa Touch
http://www.sencha.com/products/touch/
Mobile Apps - Web Apps
Thursday, May 23, 13
56. •Based on jQuery
•Light (40KB)
jQuery Mobile - Features
Mobile Apps - Web Apps
Thursday, May 23, 13
57. •Based on jQuery
•Light (40KB)
•HTML5
jQuery Mobile - Features
Mobile Apps - Web Apps
Thursday, May 23, 13
58. •Based on jQuery
•Light (40KB)
•HTML5
•Accessible (works on screen readers)
jQuery Mobile - Features
Mobile Apps - Web Apps
Thursday, May 23, 13
59. •Based on jQuery
•Light (40KB)
•HTML5
•Accessible (works on screen readers)
•Events, plugins, themes
jQuery Mobile - Features
Mobile Apps - Web Apps
Thursday, May 23, 13
60. •Based on jQuery
•Light (40KB)
•HTML5
•Accessible (works on screen readers)
•Events, plugins, themes
•Lots of documentation
jQuery Mobile - Features
Mobile Apps - Web Apps
Thursday, May 23, 13
69. jQuery Mobile - Page management
<body>
<!-- Start of first page -->
<div data-role="page" id="foo">
! <div data-role="content">!
! ! <p>I'm first in the source order so I'm shown as the page.
</p>!!
! ! <p>View internal page called <a href="#bar">bar</a></p>!
! </div><!-- /content -->
</div><!-- /page -->
</body>
Mobile Apps - Web Apps
Thursday, May 23, 13
70. <body>
<!-- Start of first page -->
<div data-role="page" id="foo">
! <div data-role="content">!
! ! <p>View internal page called <a href="#bar">bar</a></p>!
! </div><!-- /content -->
</div><!-- /page -->
<!-- Start of second page -->
<div data-role="page" id="bar">
! <div data-role="content">!
! ! <p><a href="#foo">Back to foo</a></p>!
! </div><!-- /content -->
</div><!-- /page -->
</body>
jQuery Mobile - Page management
Mobile Apps - Web Apps
Thursday, May 23, 13
71. jQuery Mobile - Transitions
<a href="foo.html" data-rel="dialog" data-transition="pop">Open dialog</a>
<a href="foo.html" data-rel="dialog" data-transition="slidedown">Open dialog</a>
<a href="foo.html" data-rel="dialog" data-transition="flip">Open dialog</a>
<a href="foo.html" data-rel="dialog" data-transition="fade">Open dialog</a>
Mobile Apps - Web Apps
Thursday, May 23, 13
72. jQuery Mobile - Dialogs
Mobile Apps - Web Apps
Thursday, May 23, 13
73. jQuery Mobile - Navigation bars
<div data-role="header" data-position="inline">
! <a href="index.html" data-icon="delete">Cancel</a>
! <h1>Edit Contact</h1>
! <a href="index.html" data-icon="check">Save</a>
</div>
Mobile Apps - Web Apps
Thursday, May 23, 13
74. jQuery Mobile - Forms
Mobile Apps - Web Apps
Thursday, May 23, 13
75. jQuery Mobile - Forms
Mobile Apps - Web Apps
Thursday, May 23, 13
76. jQuery Mobile - Lists
Mobile Apps - Web Apps
Thursday, May 23, 13
91. Mobile Apps - Web Apps
MobileDetectBundle
public function indexAction()
{
$em = $this->get('doctrine')->getEntityManager();
// ...
$mobileDetector = $this->get('mobile_detect.mobile_detector');
$tpl = $mobileDetector->isMobile() ? ‘mhtml’ : ‘html’;
return $this->render('DemoBundle:Default:index.'.$tpl.'.twig', array(
// ...
));
}
Thursday, May 23, 13
92. Mobile Apps - Web Apps
MobileDetectBundle
{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iphone') %} # magic methods is[...]
{% extends is_mobile() ? "MyBundle:Layout:mobile.html.twig" :
"MyBundle:Layout:full.html.twig" %}
Thursday, May 23, 13
93. Mobile Apps - Web Apps
MobileDetectBundle
mobile_detect:
redirect:
mobile:
is_enabled: true
host: http://m.site.com
status_code: 301
action: redirect
tablet: ~
switch_device_view: ~
Thursday, May 23, 13
94. •Symfony2 functional tests for HTML pages
•For AJAX other testing methods may be used:
•Selenium RC
•Behat
Mobile Apps - Web Apps
Testing
Thursday, May 23, 13
101. Mobile Apps - Native Apps
PHP does not run in these
devices but native apps need to
retrieve and store data from
servers.
Thursday, May 23, 13
102. Common uses:
•send emails & messages in general
•loading of profile data
•authentication & authorization
•chats
Mobile Apps - Native Apps
PHP does not run in these
devices but native apps need to
retrieve and store data from
servers.
Thursday, May 23, 13
103. Some considerations:
•Design API (RESTful, HTTP, XML-RPC) early on at
the development cycle
Mobile Apps - Native Apps
Thursday, May 23, 13
104. Some considerations:
•Design API (RESTful, HTTP, XML-RPC) early on at
the development cycle
•APIs can be used by multiple types of clients
Mobile Apps - Native Apps
Thursday, May 23, 13
105. Some considerations:
•Design API (RESTful, HTTP, XML-RPC) early on at
the development cycle
•APIs can be used by multiple types of clients
•Re-use controllers and use _format to generate
different content types (XML, JSON, etc)
Mobile Apps - Native Apps
Thursday, May 23, 13
106. Build APIs with Symfony2
- FOSRestBundle
https://packagist.org/packages/friendsofsymfony/rest-
bundle
- ApiDocBundle
https://packagist.org/packages/nelmio/api-doc-bundle
Mobile Apps - Native Apps
Thursday, May 23, 13
107. Build APIs with Symfony2
- FOSRestBundle
https://packagist.org/packages/friendsofsymfony/rest-
bundle
- ApiDocBundle
https://packagist.org/packages/nelmio/api-doc-bundle
Mobile Apps - Native Apps
Build APIs with Silex
- responsible-service-provider
- silex-skeleton-rest
Thursday, May 23, 13
108. Push Notifications
Server sends messages to mobile devices
- AppleApnPushBundle
- RMSPushNotificationsBundle
- DABSquaredPushNotificationsBundle
- ZendServiceGoogleGcm
- ZendServiceAppleApns
Mobile Apps - Native Apps
Thursday, May 23, 13
109. Mobile Apps - Native Apps
RMSPushNotificationsBundle
public function pushAction()
{
$message = new iOSMessage();
$message->setMessage('Oh my! A push notification!');
$message-
>setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5f
b448fe505eb4asdfef8595a7');
$this->container->get('rms_push_notifications')-
>send($message);
return new Response('Push notification sent!');
}
Thursday, May 23, 13
110. Mobile Apps - SMS Apps
&
SMS (and voice) Applications
Thursday, May 23, 13
114. Mobile Apps - SMS Apps
VreshTwilioBundle
$twilio = $this->get('twilio.api');
$message = $twilio->account->sms_messages->create(
'9991231234', // From a valid Twilio number
'8881231234', // Text this number
"Hello monkey!"
);
Thursday, May 23, 13
115. Mobile Apps - Voice Apps
Twilio-php SDK
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create(
'9991231234', // From a valid Twilio number
'8881231234', // Call this number
// Read TwiML at this URL when a call connects (hold music)
'http://twimlets.com/holdmusic?
Bucket=com.twilio.music.ambient'
);
Thursday, May 23, 13
116. MMS are multimedia messages with text,
images, video, audio.
Common uses:
- Photo processing
- Sending/scanning 2D barcodes
Mobile Apps - SMS/MMS Apps
https://github.com/endroid/QrCode
https://github.com/endroid/EndroidQrCodeBundle
https://github.com/mkoppanen/php-zbarcode
Thursday, May 23, 13
117. Mobile Apps - Hybrid Apps
&
Hybrid Applications
(mix native, web, others)
Thursday, May 23, 13
118. Applications that combine web, sms,
voice and native aspects
Framework PhoneGap
- Build apps with HTML & JavaScript
- Integrates with XCode
- Compiles app into native code
- Access to accelerometer, camera, geolocation,
notifications and more
Mobile Apps - Hybrid Apps
Thursday, May 23, 13