Desktop Apps with PHP and Titanium (ZendCon 2010)

42
Ben Ramsey • Zend/PHP Conference & Expo • 2 Nov 2010 Desktop Apps with PHP and Titanium

description

Appcelerator Titanium is an open source platform for developing native desktop and mobile applications using the web technologies you're familiar with. Web developers can use their skills to develop for both the Web and desktop/mobile apps. Ben Ramsey will demonstrate a simple application in Titanium Desktop, showing examples using JavaScript and PHP to power dynamic desktop applications.

Transcript of Desktop Apps with PHP and Titanium (ZendCon 2010)

Page 1: Desktop Apps with PHP and Titanium (ZendCon 2010)

Ben Ramsey • Zend/PHP Conference & Expo • 2 Nov 2010Desktop Apps with PHP and Titanium

Page 2: Desktop Apps with PHP and Titanium (ZendCon 2010)

What Is Titanium?

Page 3: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 4: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 5: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

Four main parts…

‣HTML/CSS/JavaScript

‣APIs

‣Language-OS bridge

‣Run-time shell

5

Page 6: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 7: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 8: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 9: Desktop Apps with PHP and Titanium (ZendCon 2010)

$9M in funding fromSierra Ventures and eBay!

Page 10: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 11: Desktop Apps with PHP and Titanium (ZendCon 2010)

Using Titanium Developer

Page 12: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 13: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 14: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 15: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 16: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 17: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 18: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 19: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

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*

19

Page 20: Desktop Apps with PHP and Titanium (ZendCon 2010)

“Hello, World!”

Page 21: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 22: Desktop Apps with PHP and Titanium (ZendCon 2010)

<html><head> <title>Hello, World!</title></head><body> <h1>Hello, World!</h1></body></html>

Page 23: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 24: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 25: Desktop Apps with PHP and Titanium (ZendCon 2010)

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;

Page 26: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 27: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

Titanium has APIs!

‣API

‣Analytics

‣App

‣Codec

‣Database

‣Desktop

‣Filesystem

‣JSON

‣Media

‣Network

‣Notification

‣Platform

‣Process

‣UI

‣UpdateManager

‣Worker

27

Page 28: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 29: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 30: Desktop Apps with PHP and Titanium (ZendCon 2010)

PHP in Titanium

Page 31: Desktop Apps with PHP and Titanium (ZendCon 2010)

<script type="text/php"> // PHP code goes here</script>

Page 32: Desktop Apps with PHP and Titanium (ZendCon 2010)

<script type="text/javascript"> var heading = document.getElementById("title"); heading.innerHTML = "Hello, World!";</script>

Page 33: Desktop Apps with PHP and Titanium (ZendCon 2010)

<script type="text/php"> $heading = $document->getElementById("title"); $heading->innerHTML = "Hello, World!";</script>

Page 34: Desktop Apps with PHP and Titanium (ZendCon 2010)
Page 35: Desktop Apps with PHP and Titanium (ZendCon 2010)

<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>

Page 36: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

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

36

Page 37: Desktop Apps with PHP and Titanium (ZendCon 2010)

The client-serverrelationship does not exist.

Page 38: Desktop Apps with PHP and Titanium (ZendCon 2010)

Planet PHP Demo

Page 39: Desktop Apps with PHP and Titanium (ZendCon 2010)

Wrapping up…

Page 40: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

Questions?

‣ I blog at benramsey.com.

‣ I tweet at @ramsey.

‣Please rate this presentation at joind.in/2259.

‣Get the source code for my examples at GitHub.

‣Find out more about Titanium at appcelerator.com.

‣My company is Moontoast. Check us out at moontoast.com. Follow us on Twitter and like us on Facebook.

40

Page 41: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and TitaniumCopyright © 2010 Ben Ramsey. Some rights reserved.Presented on November 2, 2010 at Zend/PHP Conference and Expo, Hyatt Regency Hotel, Santa Clara, CA.

This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.

For uses not covered under this license, please contact the author.

Page 42: Desktop Apps with PHP and Titanium (ZendCon 2010)

Desktop Apps with PHP and Titanium • Ben Ramsey

Photo Credits

‣ Titan-crystal bar from Wikimedia Commons

‣ Titanium-cylinder from Wikimedia Commons

‣ Apollo 17 full Earth photograph from NASA/Goddard Space Flight Center Scientific Visualization Studio

‣ titanium cylinder, GRADE 2 quality from Wikimedia Commons

‣ Surface of a compressed cylinder of titanium from High-Res Images of Chemical Elements

‣ Guggenheim Museum Bilbao from Wikimedia Commons

42