Including 3rd Party Libraries

I am trying to include a 3rd party library for use in some blank php apps in SC. So there is a x.php file that needs to be included and I went ahead to add this from Tools --> Libraries at the Public level.

However I get this warning when I upload the file “This library contains codes out of the functions that will only be processed through the sc_include macro”.

When I try to use the library in a blank app by checking the box in the blank app at Programming --> Libraries, I keep getting undefined variables errors following the instantiation calls e.g.

$color = new \uiwidgets\UI\DropDownList(‘color’);

There is no difference when I use require_once within onExecute viz.

<?php require_once ‘lib/uiwidgets/x.php’; ?> inside a multiline echo statement.

Please does anyone have experience with this problem and suggestions on what I can do?

Thanks

Generally you can put your library in the _lib/prod/third/ dir but be aware that it can be deleted upon a complete deployment.

When you get that message, as well as ticking the library in Programming | Libraries, you need to add the following in the onApplicationInit event:

sc_include(xxxxx.php);

(I believe you shouldn’t then need to do rr’s suggestion if you do this - although a valid way around it. Also means you do not need to worry about re-deployment removing your lib)

1 Like

Thanks - using sc_include that fixed the issue nicely!