Desktop Apps with PHP and Titanium

24,038 views

Published on

The Web is a vital part of our daily lives, and as we begin using the Web for tasks traditionally performed on the desktop, such as word processing, software as a service (SaaS) and software + services models are becoming more important. Web developers are caught in the cross hairs of these merging industries. They have the know-how of web development but, often, none of the skills for traditional desktop or mobile development.

Enter Titanium. Appcelerator Titanium is an open source platform for developing native desktop and mobile applications using the web technologies you're already familiar with. Now, web developers can use their skills to develop for both the Web and desktop/mobile platforms. Ben Ramsey will demonstrate how to create a simple application in Titanium Desktop, showing examples using JavaScript and PHP working together in the Titanium run time environment to power dynamic desktop applications that communicate easily with external web services.

Published in: Technology
3 Comments
14 Likes
Statistics
Notes
No Downloads
Views
Total views
24,038
On SlideShare
0
From Embeds
0
Number of Embeds
86
Actions
Shares
0
Downloads
513
Comments
3
Likes
14
Embeds 0
No embeds

No notes for slide

Desktop Apps with PHP and Titanium

  1. 1. Desktop Apps with PHP and Titanium Ben Ramsey TEK·X • May 19, 2010
  2. 2. Hi, I’m Ben. benramsey.com @ramsey joind.in/1576
  3. 3. DISCLAIMER: I’m not a salesman & I don’t work for Appcelerator.
  4. 4. DISCLAIMER: I helped with the initial embedding of PHP in Titanium.
  5. 5. What is Titanium?
  6. 6. Four main parts of Titanium apps • The html/css/javascript code that makes up the core application logic and UI • The APIs that access native device/ desktop functionality, analytics or other modular functionality • The language-OS bridge that compiles web code into native application code • The run-time shell that packages the application for cross-platform distribution
  7. 7. Contrasting with AIR... • Titanium is released under an open source license • Titanium provides access to native controls • Titanium applications are packaged for a target system: Windows, OS X, Linux
  8. 8. Who is Appcelerator?
  9. 9. Appcelerator’s role • Developed and own’s Titanium source • Licenses Titanium under Apache license • Support, training, and consulting • Analytics and tracking • Infrastructure for building and packaging releases of your apps in the cloud
  10. 10. How Appcelerator makes money...
  11. 11. So, why PHP on Titanium?
  12. 12. • Titanium already had modules to support Python and Ruby development • PHP was on their roadmap • PHP is a natural scripting complement to other web technologies • It was cool and fun to do • I can now build desktop apps with PHP without using PHP-GTK (no offense to the maintainers of PHP-GTK)
  13. 13. Using Titanium Developer
  14. 14. • Fill out your application details • Click “Create Project” • Click the “Test & Package” tab • Click the “Launch App” button
  15. 15. Now, you have code!
  16. 16. Installation on Linux • There is a known issue with the GTK libraries for Titanium Developer on Linux • Until there is a fix, do this after installing Titanium Developer: • cd ~/.titanium/runtime/linux/1.0.0 • rm libgobject* libgthread* libglib* libgio*
  17. 17. “Hello, World.”
  18. 18. <html> <head> <title>Hello, World!</title> </head> <body> <h1>Hello, World!</h1> </body> </html>
  19. 19. var mainMenu = Titanium.UI.createMenu(); mainMenu.appendItem(Titanium.UI.createMenuItem("File")); var menu = Titanium.UI.createMenu(); menu.appendItem(Titanium.UI.createMenuItem("Quit", function() { if (confirm("Are you sure you want to quit?")) { Titanium.App.exit(); } })); mainMenu.getItemAt(0).setSubmenu(menu); Titanium.UI.currentWindow.menu = mainMenu;
  20. 20. Titanium provides APIs... • API • Media • Analytics • Network • App • Notification • Codec • Platform • Database • Process • Desktop • UI • Filesystem • UpdateManager • JSON • Worker
  21. 21. Drop in external libraries
  22. 22. Accessing these APIs and libraries • JavaScript • Python • Ruby • PHP
  23. 23. PHP in Titanium
  24. 24. <script type="text/php"> // PHP code goes here </script>
  25. 25. JavaScript <script type="text/javascript"> var heading = document.getElementById("title"); heading.innerHTML = "Hello, World!"; </script>
  26. 26. PHP <script type="text/php"> $heading = $document->getElementById("title"); $heading->innerHTML = "Hello, World!"; </script>
  27. 27. phpinfo()
  28. 28. <html> <head> <title>PHP Info</title> <script type="text/php"> date_default_timezone_set('America/Chicago'); ini_set('default_charset', 'utf8'); ini_set('display_errors', 'Off'); function getPhpInfo() { ob_start(); phpinfo(); return ob_get_clean(); } </script> </head> <body style="background-color: white; padding: 10px;"> <script type="text/php"> $document->write('<pre>' . getPhpInfo() . '</pre>'); </script> </body> </html>
  29. 29. PHP caveats • echo does not work as expected • Titanium state transitions (links) do not send requests • Pre-processed scripts (.php) are processed at compile/build time • Cannot inject classes defined in .php into runtime code with include/require
  30. 30. Are some of these bugs? Maybe.
  31. 31. Planet PHP Demo
  32. 32. Wrapping up... • Titanium allows web developers the ability to create desktop apps • It builds native applications that you can distribute for a particular OS • You can combine PHP with JavaScript (and Python and Ruby) to leverage the best of each language • Still some bugs to iron out, but that’s why they need lots of people using it
  33. 33. Questions?
  34. 34. Thank you! Ben Ramsey benramsey.com @ramsey joind.in/1576 www.appcelerator.com developer.appcelerator.com #titanium_app on Freenode IRC

×