duanhuan1147 2014-10-02 23:37
浏览 61
已采纳

Opencart 2.0从admin或前端获取配置值也是Permission

Is it possible in opencart 2.0 to get the value from the settings. For example as it was in previous opencart versions I could store value to database via settings, thus I did not need any model file to write to database and then from anywhere I could get the value by:

$this->config->get('key_that_you_need');

... Now this still works but only when in controller. What I need is to get the value even when I'm in template file (*.tpl)

When I want to use this in *.tpl file I get this error:

Notice: Undefined property: Loader::$config

same situation applies for permissions... now you can't use this example from template:

<?php if($this->user->hasPermission('access','catalog/attribute')) { ?>

...however it is still functional in controller file

Does anyone know if it is possible or some workaround ?

  • 写回答

1条回答 默认 最新

  • dpvr49226 2014-10-03 00:12
    关注

    You shouldn't be using it in your template in the first place - You should be setting the data for the in your controller and passing that to the template. However You can do this pretty easily. Firstly, you need to bring the $config variable into the template and then call it directly, not use $this

    <?php
    global $config;
    $somevar = $config->get('key_that_you_need');
    ?>
    

    Not tested but should still work just fine

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析