自定义图像未显示在Magento2中

自定义图像未显示在Magento2中,magento,magento2,Magento,Magento2,我在phtml文件中添加了一个自定义图像,并运行命令php-bin/magento-setup:static-content:deploy,但它仍然没有显示出来。此外,此命令需要花费大量时间才能完成。如果有人想使用ui\u组件添加图像列,请按照以下说明进行操作: 在uiComponent xml中添加图像列: <column name="imagefile" class="{Namespace}\{ModuleName}\Ui\Component\Listing \Column\Thu

我在phtml文件中添加了一个自定义图像,并运行命令php-bin/magento-setup:static-content:deploy,但它仍然没有显示出来。此外,此命令需要花费大量时间才能完成。

如果有人想使用ui\u组件添加图像列,请按照以下说明进行操作:

在uiComponent xml中添加图像列:

 <column name="imagefile" class="{Namespace}\{ModuleName}\Ui\Component\Listing  \Column\Thumbnail">
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
            </item>
             <item name="config" xsi:type="array">
                <item name="sortable" xsi:type="boolean">true</item>
                <item name="altField" xsi:type="string">imagefile</item>
                <item name="has_preview" xsi:type="string">1</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="align" xsi:type="string">left</item>
                <item name="laem>bel" xsi:type="string" translate="true">Thumbnail</item>

            </item>
        </argument>
    </column>
在给定路径创建列文件,即

   <?php
   namespace {NameSpace}\{ModuleName}\Ui\Component\Listing\Column;
   use Magento\Framework\View\Element\UiComponentFactory;
   use Magento\Framework\View\Element\UiComponent\ContextInterface;
   use {NameSpace}\{ModuleName}\Model\News\Image as KtplImage;
  class Thumbnail extends \Magento\Ui\Component\Listing\Columns\Column
  {
 const NAME = 'imagefile';
 const ALT_FIELD = 'imagefile';
    public function __construct(
    ContextInterface $context,
    UiComponentFactory $uiComponentFactory,
    KtplImage $imageFactory,
    \Magento\Framework\UrlInterface $urlBuilder,
    array $components = [],
    array $data = []
) {
    parent::__construct($context, $uiComponentFactory, $components, $data);
    $this->imageFactory = $imageFactory;
    $this->urlBuilder = $urlBuilder;
}

/**
 * Prepare Data Source
 *
 * @param array $dataSource
 * @return void
 */
public function prepareDataSource(array & $dataSource)
{
    if (isset($dataSource['data']['items'])) {
        $fieldName = $this->getData('name');
        foreach ($dataSource['data']['items'] as & $item) {
            $itemIndex = new \Magento\Framework\Object($item);
            $item[$fieldName . '_src'] =   $this->imageFactory->getBaseUrl().$itemIndex->getImagefile();
            $item[$fieldName . '_orig_src'] =  $this->imageFactory->getBaseUrl().$itemIndex->getImagefile();                
        }
     }
  }

}
 use Magento\Framework\App\Filesystem\DirectoryList;
 use Magento\Backend\App\Action;
 protected $_fileUploaderFactory;
 public function __construct(
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
Action\Context $context     
 ) {
  $this->_fileUploaderFactory = $fileUploaderFactory;
  parent::__construct($context);
}
 public function execute(){
 $uploader = $this->_fileUploaderFactory->create(['fileId' => 'image']);
 $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
 $uploader->setAllowRenameFiles(false);
 $uploader->setFilesDispersion(false);
 $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)
 ->getAbsolutePath('images/');
 $uploader->save($path);
 }

如何添加自定义图像,请描述代码和文件。另外,如何在phtml文件中调用路径更为重要