Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

[Desktop] PHP embed class (3rd Party)

I was reviewing this guide: http://developer.appcelerator.com/doc/desktop/php and I was unable to reproduce. For instance I took a premade class from SF (getID3) and tried to use it as a it described and was never able to access its functions. Is this a known issue?

— asked July 13th 2010 by Merhawie Woldezion
  • desktop
  • include
  • kroll
  • php
0 Comments

3 Answers

  • Its funny that this hasn't been answered in 10 months, and has nearly 200 views.. I seem to have the same issue, I get "Couldn't execute function krollnamespace__1\testexample" when I try to call testexample(); from within a javascript block, and with my php function testexample in a block before or after.. The ironic part, is it works the other way, js objects can be used in php, but php functions cant be used in js… It would be great if I could figure this out.. But the examples I expected to work, dont… and it's another example I have found that has done this to me on this site :/ I think someone needs to re-think their documentation…

    — answered April 14th 2011 by KC Childers
    permalink
    0 Comments
  • Well I think I've figured it out. All you have to do is create an instance in the class file of that class and assign it a variable. Then you will be able to access that instance of a class in the other files.

    class myclass{
    function
    }

    $class = new myclass();

    and then in
    index.html

    echo $class->function;

    — answered April 17th 2011 by Andrey Ploskov
    permalink
    0 Comments
  • I think the answer for this would be the answer from this other question on here. http://developer.appcelerator.com/question/119717/desktop-php-including-classphp-files-and-the-kroll-namespace-error.

    Basically, if you include("a_php_file.php"); within a <script type="text/php"></script> block, or if you do it within the preprocessed php (not 100% sure on that, but I wouldn't see how this would differ). Then to gain access to those functions, and not get the "krollnamespace1\functionNameCalled" error, you simply call the function with a backslash () before the function name. Just like you would do if you were to try and call it specifically from the krollnamespace, but in the case of no namespace, its the root namespace.

    So to call "functionNameCalled();", if it resides in an included() php file, you would simply do "\functionNameCalled();"

    — answered May 16th 2011 by KC Childers
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.