How to use own PHP class - help needed - urgent

Hi Guys,

I would like to use external library wrote by me.
Could you please help to include it?

class is simple, with constructor:



class MyClass {

    public $something;

    function __contruct($var) {
       $this->something = $var;
    }

    function setSomething() {
       return $this->something;
    }


}

I would like to use it in Form’s AjaxEvent:


AjaxEvent -> field_onChange

$c = new MyClass("123");
{field} = $c->setSomething;


When I trying to run Form, i have an error:

Parse error: syntax error, unexpected ‘$c’ (T_VARIABLE) in C:\Program Files\NetMake… (long path to Form.apl.php)

What I do:

  1. SC8 > Tools > Libraries > i added MyClass.class.php in “Public”
  2. I assigned MyClass.class.php in Form > Programming > Libraries

but propably something is wrong, maybe I don’t understand how to do it correctly.

Please help.
Thank you,

daretzki (Darek)

Hi, i have a script and it worked.

If you wish use the class global example in login you must:

  • Programming / Library / mark class name for include

  • In event onvalidatesuccess, initialize variable global for class

[test] = serialize(new myclass());

In a event of a form

$clase = unserialize([test]);
$valor = $clase->SetCol(2);
[test] = serialize($clase);

De esta forma se hace uso de la clase

using the class

$global = unserialize([global_class]);
$banco = $global->getBanco();

if(({lvd_tpoentrda} == $banco) && (!{BAN_CDGO} > 0)) {
// sc_error_message(“Por favor especifique el banco”);
sc_error_message(“text malo”);
}

Thank you.

But i need use it in AjaxEvents not in Form Events. I am looking for good example how to do it.

Hi again,

my false! Broken “-” sign in one row.

nr_konta_onChange (Ajax Events)

before:



if (empty({nr_konta}))
{
	{nr_konta} = "37114020040000310242321556";
} else {
	/* class initialization below */
        $n = new NRB({nr_konta});
        /* --- */
	if ($n->poprawny()) {
		{nr_konta} = $n->formatuj();
 		{nazwa_banku}  $n->dekodujNazwe(); <--------- error there
 	} else {
		{nr_konta} = ''; 
 		{nazwa_banku} = "
$n->blad: ".$n->formatuj();
 	}
}


after:



if (empty({nr_konta}))
{
	{nr_konta} = "37114020040000310242321556";
} else {
	$n = new NRB({nr_konta});
	if ($n->poprawny()) {
		{nr_konta} = $n->formatuj();
 		{nazwa_banku} = $n->dekodujNazwe();   <-------- corrected
 	} else {
		{nr_konta} = ''; 
 		{nazwa_banku} = "
$n->blad: ".$n->formatuj();
 	}
}


Sorry.
I will write short HOW-TO use classes in SC soon.

daretzki

[SOLVED] How to use own PHP class - help needed - urgent

Hi again,

my false! Broken “-” sign in one row.

nr_konta_onChange (Ajax Events)

before:



if (empty({nr_konta}))
{
	{nr_konta} = "37114020040000310242321556";
} else {
	/* class initialization below */
        $n = new NRB({nr_konta});
        /* --- */
	if ($n->poprawny()) {
		{nr_konta} = $n->formatuj();
 		{nazwa_banku}  $n->dekodujNazwe(); <--------- error there
 	} else {
		{nr_konta} = ''; 
 		{nazwa_banku} = "
$n->blad: ".$n->formatuj();
 	}
}


after:



if (empty({nr_konta}))
{
	{nr_konta} = "37114020040000310242321556";
} else {
	$n = new NRB({nr_konta});
	if ($n->poprawny()) {
		{nr_konta} = $n->formatuj();
 		{nazwa_banku} = $n->dekodujNazwe();   <-------- corrected
 	} else {
		{nr_konta} = ''; 
 		{nazwa_banku} = "
$n->blad: ".$n->formatuj();
 	}
}


Sorry.
I will write short HOW-TO use classes in SC soon.

daretzki

you promised - right ?
so where is it ?