Skayfer Posted September 24, 2015 Share Posted September 24, 2015 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 More sharing options...
Skayfer Posted September 25, 2015 Author Share Posted September 25, 2015 Can anyone help ? Maybe i can use only context object ? It has this same functionality as gloabel var ? Link to comment Share on other sites More sharing options...
Skayfer Posted September 25, 2015 Author Share Posted September 25, 2015 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 More sharing options...
JoelWebsites Posted September 26, 2015 Share Posted September 26, 2015 Hi global variables are forbidden in Prestashop modules however you can use below code format for variable to serve the same purpose. $this->context->cookie->variablename Link to comment Share on other sites More sharing options...
Skayfer Posted September 28, 2015 Author Share Posted September 28, 2015 Thanks Joel, now it is easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now