Jump to content

Creat global variable in module


Skayfer

Recommended Posts

Hi,

 

I write my module in which i have main class with a lot of fucntions. In almost every function i use var with number of result row:

 

$sql = "SELECT value FROM ps_configuration WHERE name LIKE '%MY_VALUE%'";
$result = Db::getInstance()->ExecuteS($sql);
$liczba_wierszy = DB::getInstance()->NumRows($result);

It works ok, but i would like write this module better, i dont want duplicate this code. I would like declare var $liczba_wierszy in one function and can use it in other functions in my module.

 

It is possible ?

 

Thanks for answers :)

 

Link to comment
Share on other sites

I resolve my problem with

https://www.prestashop.com/forums/topic/156171-new-global-var/

, but i add modification. Cart expert not add global to first declaration of var. I test it and i must add global.

 

In step for other:

1. Outside main class i execute my code, declare "global $var", and assign result to "$var".

2. In each function in i want use this var, i must declare "global $var" and i can use "$var"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...