0

I have a problem that i do not know how to create a template file that has a button to browser the computer, so user can select a file on the computer in order to upload. Can anybody help me to make this, please. i have created controller file:

<?php

namespace Vendor\Module\Controller\Adminhtml\File;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;

class Import extends \Magento\Backend\App\Action
{
    /**
     * @var \Magento\Framework\Registry
     */
    private $coreRegistry;

    /**
     * Import constructor.
     * @param Context $context
     * @param \Magento\Framework\Registry $coreRegistry
     */
    public function __construct(Context $context,  \Magento\Framework\Registry $coreRegistry)
    {
        $this->coreRegistry = $coreRegistry;
        parent::__construct($context);
    }

    /**
     * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
        $resultPage->getConfig()->getTitle()->prepend(__('Import Data'));
        return $resultPage;
    }
}

Block file:

<?php

namespace Vendor\Module\Block\Adminhtml\File;

use \Magento\Backend\Block\Template\Context;

class Import extends \Magento\Backend\Block\Widget
{
    /**
     * Import constructor.
     * @param \Magento\Backend\Block\Template\Context $context
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        array $data = []
    )
    {
        $this->setUseContainer(true);
        parent::__construct($context, $data);
    }
}

Layout file:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Import Data Page</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Vendor\Module\Block\Adminhtml\File\Import"
                   template="Vendor_Module::import.phtml" name="vendormodule_file_import"/>
        </referenceContainer>
    </body>
</page>

Now, my only problem is create a template file. Thank for your help.

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.