How to define own classes i sc

Hi I have som Php code that i want to put in i Button php-script in an application. This php code includes definition of a class, that is required for the purpose of the application.
The problem is that this that it seems tha sc dont accept class definition here.
Anyone knows where to put definitions of classes.

Re: How to define own classes i sc

I needed some specific custom functions that are located in non-scriptcase files to be available in scriptcase. I’m not sure if this is exactly what you need, but it worked for me:

  1. Put the custom php file in ?.scriptcasedevelconfscriptcaselib
  2. Include the file in event (for example) ?onLoad?: sc_include(customfunctions.php);
  3. now you can use your custom functions in events etc.

Can someone from Netmake confirm that this is the way to handle this? The documentation is not clear on this subject. I can find some references to “Libraries” in the online help, but it doesn’s work as documented. Maybe because this specific part of the documentation is for V3?

Re: How to define own classes i sc

No in V5 you can’t put a class definition in a event, because of the onEvent method is a member of the applicatipn class. Your class ist in this case a-class-definition in a-class-definition, thats not allowed by php.
The way over sc_include or require_once() in sc is also not a solution, because the code in the included file was not include before the app - class.
I try to check the libaries in the Programming>libaries Folder of the app navigation. I hoped thas the way to make a include in the head on the sc-created php-file. No. The libaries was not included or copiesd in a deploy version…

I have a class to start access to use the report printer function. In my PHP-IDE works it fine, but not in scriptcase.
Also Is my way, make a blank (for automatic start) or control app (for user-start), set the values for my class over the sc_set global macro and read them over $_SESSION[varname] in my class…

?This is a plan… maybee… i hope it works…

Re: How to define own classes i sc

Let us know how this turns out. There is always a way to trick your code if you are determined <BG>

Regards,
Scott.

Re: How to define own classes i sc

Here is what I have in my code to call a class in my code:

app_name.onInit():


$reg_file = '../rnr_php_file.php';
if (file_exists($reg_file)) {
 include($reg_file);
} 

rnr_php_file.php:



define("_FUNCTION_PATH", "../rnr_functions.php");
if(file_exists(_FUNCTION_PATH)){include_once(_FUNCTION_PATH);}
else{echo"Function file does not exist";} 


rnr_functions.php



class myclass
{
  function myfunction() { .. }
}

$myc = new myclass();

eval( $myc->myfunction( .. ) );



Something like that.

Regards,
Scott.

Re: How to define own classes i sc

I managed to use an external class with scriptcase too.
My configuration is as follows:
With MS Access, I create a PDF printer driver or OutputTo function of MS Access2007 multiple PDF files, which are to be merged with the fpdf class to a common PDF file.

Step 1:
I have a SC Library access_printer.inc.php in the functions to print the PDF reports from MS Access are included. This library I bump under Application> Programming> Libraries in my SC application. Thus the Application class is added to the functions contained in the library.

Step2:
The SC Macro sc_set_global I now set the values, what is to be used by the external class. In my case, the list containing the names of the PDF files as php array and some parameters to control the fpdf class.
The external class, I now call on the sc_redir macro.
In order to find the macro, the php scripts, these must be integrated into the folder structure of scriptcase development environment.
Example:
Name of the script: php_merger.php
Folder Location: / netmake/v5/scriptcase/projectname/app/pdf_merger

It is important that is used in the external php script session_start () so the class can access the session variables.
In the SC session variable, I will touch it with $ _SESSION [ ‘varname’ to].
That works just fine!

Step 3:
The important thing is not that you do not forget the php files of the external class when deploy manually in the zip file must be copied, otherwise they will be missing in the production environment.