Announcement

Collapse
No announcement yet.

Usage of php one method in many applications

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

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

  • #2
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.
        Best regards,

        Frank

        Comment


        • #5
          Originally posted by Orion View Post
          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
          /Giuseppe

          Professional Scriptcase Services
          Some Customers opinions

          Comment


          • #6
            Originally posted by Giu View Post
            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?
            Best regards,

            Frank

            Comment


            • #7
              Originally posted by Orion View Post
              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.
              /Giuseppe

              Professional Scriptcase Services
              Some Customers opinions

              Comment


              • #8
                Originally posted by Giu View Post
                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
                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?

                Comment


                • #9
                  Originally posted by Giu View Post
                  I mean what was called Libraries, and since last version now is called Scripts, because SC use library concept for other thing inside SC.
                  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.
                  Best regards,

                  Frank

                  Comment


                  • #10
                    Originally posted by magezi View Post
                    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?
                    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.
                    Best regards,

                    Frank

                    Comment


                    • #11
                      Originally posted by Orion View Post
                      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.
                      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
                      /Giuseppe

                      Professional Scriptcase Services
                      Some Customers opinions

                      Comment


                      • #12
                        Originally posted by Giu View Post
                        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.
                        Ah well, I was hoping SC would include any files before converting.
                        Best regards,

                        Frank

                        Comment


                        • #13
                          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.
                          Last edited by magezi; 10-05-2015, 08:56 AM.

                          Comment


                          • #14
                            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?
                            Best regards,

                            Frank

                            Comment


                            • #15
                              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

                              Comment

                              Working...
                              X