Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setting global variables in OpenCart 2.3.0.2?

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.

like image 720
user3807124 Avatar asked Jan 28 '26 15:01

user3807124


1 Answers

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.

like image 179
Kim Hoogenberg Avatar answered Jan 31 '26 05:01

Kim Hoogenberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!