【发布时间】:2021-12-03 10:09:07
【问题描述】:
我有一个 magento 扩展,我想在其中一个控制器中显示 setup_version。
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="My_Module" setup_version="0.0.3"/>
</config>
在控制器内部:
<?php
namespace My\Module\Controller\Index;
use Magento\Framework\App\Config\ScopeConfigInterface;
class Version extends AbstractIndex
{
/**
* @var ScopeConfigInterface
*/
protected $storeConfig;
public function __construct(ScopeConfigInterface $storeConfig)
{
$this->storeConfig = $storeConfig;
}
public function execute() {
// just prints the version
echo (string)$this->storeConfig->getValue('modules/My_Module/setup_version');
}
}
但显然我确实得到了一个错误:
错误:在 /home/alexandru/magento24/vendor/magento/framework/App/Action/Action.php:109 中的 null 上调用成员函数 get()
【问题讨论】:
标签: magento2