Skip to main content
3 of 3
added 81 characters in body

Magento 2.3: How To Get The Primary Key From URL...?

I'm very new to Magneto 2.3, I'm trying to get the primary key from URL, this is my code:

This is my import button, on click of this button, a function hit.

/app/code/EC/Customimport/view/adminhtml/templates/form/import.phtml

<div class="pp-buttons-container">
    <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
        <span><span><span><?php echo 'Import'; ?></span></span></span>
    </button>
</div>
<script type="text/javascript">
    require(["jquery",'mage/url'], function($, url){
        "use strict";
        $(document).on('click','.col-action-grouped a',function(){
        });

        $(document).on('click','.import',function(){
            jQuery.ajax({
            url: '/admin/customimport/index/import',
            type: "POST",
            data: data: {url_value : url},
            success: function(response){
                console.log('ABCD');
            }
        });
        });
        
    });
</script>

This is the file and in that file their is a function execute, where I'm trying to get the primary key, please see the code below:

/app/code/EC/Customimport/Controller/Adminhtml/Index/Import.php

<?php

namespace EC\Customimport\Controller\Adminhtml\Index;

use EC\Customimport\Model\CustomimportFactory;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;

class Import extends \Magento\Backend\App\Action
{
    protected $request;

    /**
     * @param Context $context
     */
    public function __construct(
        \Magento\Framework\App\Request\Http $request,
        Context $context,
        CustomimportFactory $modelCustomimportFactory
    ) {
        $this->request = $request;
        $this->modelCustomimportFactory = $modelCustomimportFactory;
        $this->resultFactory = $context->getResultFactory();
        parent::__construct($context);
    }

    public function execute(){
        ignore_user_abort(true);
        set_time_limit(0);

        //$id = $this->request->getParams('customimport_id'); 
        //print_r($id);
        //exit;

        $postData = $this->getRequest()->getPost(); 
        $id = $postData['customimport_id'];
        print_r($id);
        exit;
    }
}

enter image description here