How to setting global variables in OpenCart 2.3.0.2?

旧巷老猫 提交于 2019-12-07 12:32:11

问题


When I want to set a global variable in template (.tpl files), I just use global in opencart 2.2 or older version.

For example:

<?php global $config; if($config->get('my_options')== 1) { ?>....<?php } ?>

but, it does not work in Latest OpenCart 2.3.0.2

Because predefined global $config in controller rather inconvenient (we have use config value in many template file). Hopefully someone with more experience will have an answer to this problem.


回答1:


The least code you will get defining them as constants in config.php or admin/config.php, depending on where you will need them. This will make these constants immediately available throughout the catalog or admin context.

Another way is by using $this->config in controllers to get key/values out of the setting table into your models or controllers.



来源:https://stackoverflow.com/questions/38830286/how-to-setting-global-variables-in-opencart-2-3-0-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!