Edge_jr Posted May 19, 2015 Share Posted May 19, 2015 (edited) Hi, I am not able to use global variable in my module ,it gives error in prestashop validator as "Use of globals is forbidden" I am using global $smarty;global $cookie, $_LANGADM; and prestashop code files used global $_MODULES; I am getting blank screen when global is remove from smarty variable. Following giving blank screen $this->smarty->assign('MYTEXT_TEXT', $mymodule); return $this->smarty->display(__FILE__, './views/templates/front/mymodule.tpl'); Please help on using smarty and other variable without global -Thanks Edited May 19, 2015 by edge82 (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted May 19, 2015 Share Posted May 19, 2015 Use $this->context->smarty $this->context->cookie $this->context->employee $this->context->link $this->context->customer $this->context->language Link to comment Share on other sites More sharing options...
Edge_jr Posted May 19, 2015 Author Share Posted May 19, 2015 (edited) Hi tuk66, Many thanks for information. Please advise on following. var $cookie,$_LANGADM,$_MODULE; $this->context->_MODULE or $this->_MODULE $this->context->_LANGADM or $this->_LANGADM -Thanks Edited May 19, 2015 by edge82 (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted May 19, 2015 Share Posted May 19, 2015 I suggest to learn from built-in modules. Usually there is no direct way, like A -> B, C -> D. Link to comment Share on other sites More sharing options...
Edge_jr Posted May 19, 2015 Author Share Posted May 19, 2015 $_MODULE and $_LANGADM variables are global variables in core PS files How to use these variable using this and context. I am getting following error Variable $_MODULE is undefined. Variable $_LANGADM is undefined. Please advise. Link to comment Share on other sites More sharing options...
bellini13 Posted May 20, 2015 Share Posted May 20, 2015 which core files? Link to comment Share on other sites More sharing options...
Edge_jr Posted May 22, 2015 Author Share Posted May 22, 2015 There are many one example is classes\module\Module.php from version 6 /** * This function is used to determine the module name * of an AdminTab which belongs to a module, in order to keep translation * related to a module in its directory (instead of $_LANGADM) * * @param mixed $currentClass the * @return boolean|string if the class belongs to a module, will return the module name. Otherwise, return false. */ public static function getModuleNameFromClass($currentClass) { // Module can now define AdminTab keeping the module translations method, // i.e. in modules/[module name]/[iso_code].php if (!isset(self::$classInModule[$currentClass]) && class_exists($currentClass)) { global $_MODULES; $_MODULE = array(); $reflectionClass = new ReflectionClass($currentClass); $filePath = realpath($reflectionClass->getFileName()); $realpathModuleDir = realpath(_PS_MODULE_DIR_); if (substr(realpath($filePath), 0, strlen($realpathModuleDir)) == $realpathModuleDir) { // For controllers in module/controllers path if (basename(dirname(dirname($filePath))) == 'controllers') self::$classInModule[$currentClass] = basename(dirname(dirname(dirname($filePath)))); // For old AdminTab controllers else self::$classInModule[$currentClass] = substr(dirname($filePath), strlen($realpathModuleDir) + 1); $file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.Context::getContext()->language->iso_code.'.php'; if (Tools::file_exists_cache($file) && include_once($file)) $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; } else self::$classInModule[$currentClass] = false; } // return name of the module, or false return self::$classInModule[$currentClass]; } Link to comment Share on other sites More sharing options...
bellini13 Posted May 22, 2015 Share Posted May 22, 2015 Variable $_MODULE is undefined. First $_MODULE is not global, $_MODULES is global, there is a big difference. Second, did you try $_MODULES ? Lastly, why would you need access to this? 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