Questions tagged «preference»

2
Magento 2:$ data数组构造函数参数是什么?
因此,我注意到在大多数模型和块中,这array $data = []是构造函数的最后一个参数。 例如 \Magento\Catalog\Block\Product\ListProduct public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, \Magento\Catalog\Model\Layer\Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Url\Helper\Data $urlHelper, array $data = [] ) { $this->_catalogLayer = $layerResolver->get(); $this->_postDataHelper = $postDataHelper; $this->categoryRepository = $categoryRepository; $this->urlHelper = $urlHelper; parent::__construct( $context, $data ); } 我还知道,在处理首选项时,当添加的参数比原始构造函数更多时,仍必须将该参数保留在构造函数参数列表的末尾。 所以我对这个数组有几个问题: 它是什么 ? 如何使用它 ? 声明添加更多参数的块的首选项时,为什么需要将其保留在构造函数参数列表的末尾?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.