$30 off During Our Annual Pro Sale. View Details »

Desktop Apps with PHP and Titanium (php|tek 2010)

Desktop Apps with PHP and Titanium (php|tek 2010)

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.

Ben Ramsey
PRO

May 19, 2010
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. Desktop Apps with
    PHP and Titanium
    Ben Ramsey

    TEK·X • May 19, 2010

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  5. What is Titanium?

    View Slide

  6. View Slide

  7. View Slide

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

    View Slide

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

    View Slide

  10. Who is
    Appcelerator?

    View Slide

  11. View Slide

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

    View Slide

  13. How Appcelerator makes money...

    View Slide

  14. So, why PHP on
    Titanium?

    View Slide

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

    View Slide

  16. Using Titanium
    Developer

    View Slide

  17. View Slide

  18. View Slide

  19. View Slide

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

    View Slide

  21. View Slide

  22. Now, you have code!

    View Slide

  23. 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*

    View Slide

  24. “Hello, World.”

    View Slide

  25. View Slide



  26. Hello, World!


    Hello, World!


    View Slide

  27. View Slide

  28. View Slide

  29. 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;

    View Slide

  30. View Slide

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

    View Slide

  32. Drop in external libraries

    View Slide

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

    View Slide

  34. PHP in Titanium

    View Slide

  35. <br/>// PHP code goes here<br/>

    View Slide

  36. <br/>var heading = document.getElementById("title");<br/>heading.innerHTML = "Hello, World!";<br/>
    JavaScript

    View Slide

  37. <br/>$heading = $document->getElementById("title");<br/>$heading->innerHTML = "Hello, World!";<br/>
    PHP

    View Slide

  38. phpinfo()

    View Slide



  39. PHP Info
    <br/>date_default_timezone_set('America/Chicago');<br/>ini_set('default_charset', 'utf8');<br/>ini_set('display_errors', 'Off');<br/>function getPhpInfo() {<br/>ob_start();<br/>phpinfo();<br/>return ob_get_clean();<br/>}<br/>


    <br/>$document->write('<pre>' . getPhpInfo() . '</pre>');<br/>


    View Slide

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

    View Slide

  41. Are some of these
    bugs?
    Maybe.

    View Slide

  42. Planet PHP Demo

    View Slide

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

    View Slide

  44. Questions?

    View Slide

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

    View Slide