Slide 1

Slide 1 text

Desktop Apps with PHP and Titanium Ben Ramsey
 TEK·X • May 19, 2010

Slide 2

Slide 2 text

Hi, I’m Ben. benramsey.com @ramsey joind.in/1576

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

DISCLAIMER: I helped with the initial embedding of PHP in Titanium.

Slide 5

Slide 5 text

What is Titanium?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Who is Appcelerator?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

How Appcelerator makes money...

Slide 14

Slide 14 text

So, why PHP on Titanium?

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Using Titanium Developer

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

• Fill out your application details • Click “Create Project” • Click the “Test & Package” tab • Click the “Launch App” button

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Now, you have code!

Slide 23

Slide 23 text

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*

Slide 24

Slide 24 text

“Hello, World.”

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Hello, World!

Hello, World!

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

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;

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Titanium provides APIs... • API • Analytics • App • Codec • Database • Desktop • Filesystem • JSON • Media • Network • Notification • Platform • Process • UI • UpdateManager • Worker

Slide 32

Slide 32 text

Drop in external libraries

Slide 33

Slide 33 text

Accessing these APIs and libraries • JavaScript • Python • Ruby • PHP

Slide 34

Slide 34 text

PHP in Titanium

Slide 35

Slide 35 text

// PHP code goes here

Slide 36

Slide 36 text

var heading = document.getElementById("title"); heading.innerHTML = "Hello, World!"; JavaScript

Slide 37

Slide 37 text

$heading = $document->getElementById("title"); $heading->innerHTML = "Hello, World!"; PHP

Slide 38

Slide 38 text

phpinfo()

Slide 39

Slide 39 text

PHP Info 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(); } $document->write('<pre>' . getPhpInfo() . '</pre>');

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

Are some of these bugs? Maybe.

Slide 42

Slide 42 text

Planet PHP Demo

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

Questions?

Slide 45

Slide 45 text

Thank you! Ben Ramsey benramsey.com @ramsey joind.in/1576 www.appcelerator.com developer.appcelerator.com #titanium_app on Freenode IRC