Magento 2 不是来自 Block 的 return 数组
Magento 2 not return array from Block
如何从 Block 发送数组并在 magento 2 中获取 Phtml 文件。我正在尝试从 Block return 数组并希望在模板 Phtml 文件中获取数组。但是他们不显示我的数据。
您需要将 区块 中的任何 public 函数定义为
public function getMyCustomData(){
$arr = [];
$arr[] = // my data;
...
...
return $arr;
}
比起在 phtml 文件中,您可以通过
调用此函数
$myCustomArr = $block->getMyCustomData();
如何从 Block 发送数组并在 magento 2 中获取 Phtml 文件。我正在尝试从 Block return 数组并希望在模板 Phtml 文件中获取数组。但是他们不显示我的数据。
您需要将 区块 中的任何 public 函数定义为
public function getMyCustomData(){
$arr = [];
$arr[] = // my data;
...
...
return $arr;
}
比起在 phtml 文件中,您可以通过
调用此函数$myCustomArr = $block->getMyCustomData();