user3807124
user3807124

Reputation: 43

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.

Upvotes: 3

Views: 2005

Answers (1)

Kim Hoogenberg
Kim Hoogenberg

Reputation: 96

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.

Upvotes: 2

Related Questions