Hi guys, for the last day I’ve been trying to see what libraries are included in PHP when I use it with Titanium Desktop. I tried for several hours at home to just display phpinfo() within my new application with no such luck. In the end I had to post on the Titanium Q&A to get a solution, luckily Alan DuBoff from Appcelerator was on hand to help me with my query.
I tried the usual (from IBM) trick of linking to the PHP page:
index.html
<a href="phpinfo.php">see PHP info</a>
phpinfo.php
<?php print phpinfo(); ?>
That sadly didn’t work, so I tried the approach from Ben Ramsey:
<script type="text/php"> ob_start(); phpinfo(); $info = ob_get_clean(); $document -> write($info); </script>
That didn’t work either! Alan mentioned updating to 1.2.0.RC3 (found here) as coding conventions have changed in the latest release. For example rather than using :
Method two
<script type="text/php" src="file.php"/>
Method three
<script type="text/php"> include("file.php"); </script>
You have the ability to use the usual Titanium.include (note: NOT Ti.include):
<script> Titanium.include("file.php"); </script>
From the Ti Wiki
When including PHP via the ‘include’ or ‘require’ commands you should surround your code with ‘<?php?>’ tags. When including via ‘<script type=”text/javascript”>’ tags, you should not surround your code with ‘<?php ?>’ tags.
Once 1.2.0.RC3 was downloaded & copied to the right location, a quick restart of TiStudio & off I went again. I used a simple jQuery to populate a html textarea to get the contents of the phpInfo so it can be copied here for everyone’s ease. Here is the full code:
index.html
<html> <head> <title>PHP Info</title> <script type="text/javascript" src="jquery.min.js"></script> <script> Titanium.include("file.php"); var infoTxt = getPhpInfo(); $(function() { $('#t').html(infoTxt); }); </script> </head> <body> <textarea id="t" cols="50" rows="40"></textarea> </body> </html>
file.php
function getPhpInfo(){ ob_start(); phpinfo(); $info = ob_get_clean(); return $info; }
Output
Here is the output of the phpInfo() on my machine: here.
Sources:
http://wiki.appcelerator.org/display/guides/Using+Titanium+Desktop+with+PHP
http://developer.appcelerator.com/blog/2011/08/introducing-titanium-desktop-sdk-1-2-release-candidate-3.html
http://developer.appcelerator.com/question/87921/integrating-third-party-libraries