Usage of php one method in many applications

Hello, I have a method that I’ll be using in almost all my applications, the problem is I don’t know where to put the script of that method, how to indicate the methode has some parameters to receive too.

SC has for you create own Libarries, you can create your libarry and include in your apps. Select TOOLS - LIBRARY - SELECT PUBLIK AND CLICK BUTTON NEW.

So I have to create a php file a part and upload it in the library but the problem is In the method I would like to use some sc macros and global variables

Well, that is not really feasible. You will have to separate concerns. Create a PHP class with a constructor method that you can supply the global variables to. If your usage of sc macros is to interact with the database, you can create a PDO connection and supply this to the constructor method of your PHP class, which can then work directly on the database. I don’t know if this is feasible for your specific method. Alternatively, you can try to use the PHP include statement and include some lines php code in a file (not a function or class). I have not tried this, as I prefer to use a class.

If you want to have your code as the new Libraries concept, and need to access database, your way is the right way, because libraries are not parsed by SC. If you want to use macros,then Scripts is the way to go

Giu, I supposed that by scripts you mean some files with PHP code that one can insert into the event triggers (OnLoad, OnApplicationInit, etc.) by using the include statement?

I mean what was called Libraries, and since last version now is called Scripts, because SC use library concept for other thing inside SC.

It is easier doing it in my way, so I have to create a php file and upload in my library? What if also I want to use macro?

Confusing. I have not yet upgraded to 8.1.

As I see it in 8.0 you can either create a PHP class add it to the library and call that (this does not allow SC macros), or you can have file with PHP code and SC macros that can probably be included via the PHP include statement in SC code sections for events, i.e. OnLoad, OnValidate, etc. I have not tried the latter as I prefer separate classes, but when I have more time I may give it a go.

Any code you include in SC’s library will be separate PHP code that cannot use SC macros (at least for 8.0).

Why don’t you save your PHP file that includes SC macros separate from SC (i.e. do not include it in the library) and include it via the PHP include or require statement (http://php.net/manual/en/function.include.php) in the code sections (i.e. OnLoad, OnValidate, etc.) where it is relevant. I have not had the need, so have not attempted this yet, but it may just work.

[QUOTE=Orion;41181]Any code you include in SC’s library will be separate PHP code that cannot use SC macros (at least for 8.0).

Why don’t you save your PHP file that includes SC macros separate from SC (i.e. do not include it in the library) and include it via the PHP include or require statement (http://php.net/manual/en/function.include.php) in the code sections (i.e. OnLoad, OnValidate, etc.) where it is relevant. I have not had the need, so have not attempted this yet, but it may just work.[/QUOTE]

Because separated files are not parsed. An sc_lookup is not really a sc_lookup function in code, is generated into some lines of code. If you want SC to convert macros to really PHP understands,you have to add t to scripts section of SC, and inlcude it in you as in Application>libraries.

Sorry,writing from mobile

Ah well, I was hoping SC would include any files before converting.

Hello I found it will be good to just use a library. After uploading the file that contains my function I tried to call one function in onafterupdate of an application which is in that file but here is the error that I am getting: “Call to undefined function name_of_function”. I really don’t know How to handle it I try to go through library example of manual there is nothing that can help me; I even tried to put include(‘libraryfile.php’) before using the method but nothing worked.

Well, one time when I first started to use libraries, I had the same problem. It turned out that I had forgot to also mark my specific library as active for in the application itself – besides loading the library file to SC which I gather that you have done already. Could that be it?

But How to activate that, I did something like going to library menu of the application and checked the file that contains my functions but nothing is working

I got the error, It was name CalculTemps() instead of calculTemps so now it is working after activating it in my application as I explained above. The only problem is scriptcase doesn’t allow you to edit your library files directely; so if there is a mistake you have to upload again(with the caching of file it is giving hard time so that the new change take place). Thanks for your support

You are welcome. I am glad that you got it to work.

You can actually edit the library directly. If you are using 8.1 you just have to select the menu-item “Scripts (Old Libraries)” in the “Tools” menu. You can then select the your old library under either ScriptCase, Public, Project or User (where you created it originally) and then proceed to edit it.