How to setting global variables in OpenCart 2.3.0.

2019-05-10 00:41发布

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条回答
做自己的国王
2楼-- · 2019-05-10 01:13

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.

查看更多
登录 后发表回答