Transcript
Page 1: Desktop Apps with PHP and Titanium

Desktop Apps with PHP and Titanium

Ben RamseyTEK·X • May 19, 2010

Page 3: Desktop Apps with PHP and Titanium

DISCLAIMER:

I’m not a salesman & I don’t work for Appcelerator.

Page 4: Desktop Apps with PHP and Titanium

DISCLAIMER:

I helped with the initial embedding of PHP in Titanium.

Page 5: Desktop Apps with PHP and Titanium

What is Titanium?

Page 6: Desktop Apps with PHP and Titanium
Page 7: Desktop Apps with PHP and Titanium
Page 8: Desktop Apps with PHP and Titanium

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

Page 9: Desktop Apps with PHP and Titanium

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

Page 10: Desktop Apps with PHP and Titanium

Who is Appcelerator?

Page 11: Desktop Apps with PHP and Titanium
Page 12: Desktop Apps with PHP and Titanium

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

Page 13: Desktop Apps with PHP and Titanium

How Appcelerator makes money...

Page 14: Desktop Apps with PHP and Titanium

So, why PHP on Titanium?

Page 15: Desktop Apps with PHP and Titanium

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

Page 16: Desktop Apps with PHP and Titanium

Using Titanium Developer

Page 17: Desktop Apps with PHP and Titanium
Page 18: Desktop Apps with PHP and Titanium
Page 19: Desktop Apps with PHP and Titanium
Page 20: Desktop Apps with PHP and Titanium

• Fill out your application details

• Click “Create Project”

• Click the “Test & Package” tab

• Click the “Launch App” button

Page 21: Desktop Apps with PHP and Titanium
Page 22: Desktop Apps with PHP and Titanium

Now, you have code!

Page 23: Desktop Apps with PHP and Titanium

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*

Page 24: Desktop Apps with PHP and Titanium

“Hello, World.”

Page 25: Desktop Apps with PHP and Titanium
Page 26: Desktop Apps with PHP and Titanium

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

Page 27: Desktop Apps with PHP and Titanium
Page 28: Desktop Apps with PHP and Titanium
Page 29: Desktop Apps with PHP and Titanium

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 30: Desktop Apps with PHP and Titanium
Page 31: Desktop Apps with PHP and Titanium

Titanium provides APIs...

• API

• Analytics

• App

• Codec

• Database

• Desktop

• Filesystem

• JSON

• Media

• Network

• Notification

• Platform

• Process

• UI

• UpdateManager

• Worker

Page 32: Desktop Apps with PHP and Titanium

Drop in external libraries

Page 33: Desktop Apps with PHP and Titanium

Accessing these APIs and libraries

• JavaScript

• Python

• Ruby

• PHP

Page 34: Desktop Apps with PHP and Titanium

PHP in Titanium

Page 35: Desktop Apps with PHP and Titanium

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

Page 36: Desktop Apps with PHP and Titanium

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

JavaScript

Page 37: Desktop Apps with PHP and Titanium

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

PHP

Page 38: Desktop Apps with PHP and Titanium

phpinfo()

Page 39: Desktop Apps with PHP and Titanium

<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 40: Desktop Apps with PHP and Titanium

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

Page 41: Desktop Apps with PHP and Titanium

Are some of these bugs?

Maybe.

Page 42: Desktop Apps with PHP and Titanium

Planet PHP Demo

Page 43: Desktop Apps with PHP and Titanium

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

Page 44: Desktop Apps with PHP and Titanium

Questions?

Page 45: Desktop Apps with PHP and Titanium

Thank you!

Ben [email protected]/1576

www.appcelerator.comdeveloper.appcelerator.com#titanium_app on Freenode IRC


Top Related