이 태그를 ui_component
레이아웃 파일 에 추가 하십시오.
<column name="logo" class="NAMESPACE\MODULENAME\Ui\Component\Listing\Columns\Logo">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
<!--<item name="add_field" xsi:type="boolean">true</item>-->
<item name="sortable" xsi:type="boolean">false</item>
<item name="altField" xsi:type="string">name</item>
<item name="has_preview" xsi:type="string">1</item>
<item name="label" xsi:type="string" translate="true">Brand Logo</item>
</item>
</argument>
</column>
ui_component
열에 할당 한이 새 파일을 만듭니다
<?php
namespace NAMESPACE\MODULENAME\Ui\Component\Listing\Columns;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
class Logo extends \Magento\Ui\Component\Listing\Columns\Column
{
const NAME = 'logo';
const ALT_FIELD = 'name';
protected $_storeManager;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
\Magento\Framework\UrlInterface $urlBuilder,
array $components = [],
array $data = [],
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_storeManager = $storeManager;
$this->urlBuilder = $urlBuilder;
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as & $item) {
$mediaRelativePath=$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$logoPath=$mediaRelativePath.$item['logo'];
$item[$fieldName . '_src'] = $logoPath;
$item[$fieldName . '_alt'] = $this->getAlt($item);
$item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
'brand/manage/edit',
['brand_id' => $item['brand_id'], 'store' => $this->context->getRequestParam('store')]
);
$item[$fieldName . '_orig_src'] = $logoPath;
}
}
return $dataSource;
}
/**
* @param array $row
*
* @return null|string
*/
protected function getAlt($row)
{
$altField = self::ALT_FIELD;
return isset($row[$altField]) ? $row[$altField] : null;
}
}
에서 prepareDataSource
기능을 각 열 개체를 얻을 것이다.
이것이 도움이되기를 바랍니다.
if($item[$fieldName] != '')
했습니다 . 내 'image'를 반환했지만 db 필드는 'url'입니다. 나머지 는 그대로 남았습니다.if($item['url'] != '')
'pathtoyourimage/'.$item[$fieldName]
'pathtoyourimage/'.$item['url']
$fieldName
$item[$fieldName . '***']