1

在以前的 Opencart 中,您可以通过简单地调用从模板 (.tpl) 中访问控制器类方法$this

$store_name = $this->config->get('config_language');

在 Opencart 2+ 中,这不再可能,因此有必要通过这里registry讨论的方式调用它们

$store_name = $this->registry->get('config')->get('config_language');

现在在 Opencart 2.3 中这也不起作用。所以我尝试简单地传递$this$data数组,这只是部分有效:

(在控制器中)

public $name = 'test';
...
$data['this'] = $this;

(在模板中)

//  The following works fine and outputs the class property $name
$this->name;

// This does not work and returns errors
// Notice: Undefined property: Template\PHP::$registry
// PHP Fatal error:  Call to a member function get() on a non-object
$this->registry->get('config')->get('config_language');

问题:为什么直接控制器类属性可用,但父类方法registry不可用?

4

0 回答 0