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:'success'},
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(); // all params
print_r($id);
exit;
$model = $this->modelCustomimportFactory->create()->load($id);
$model->import();
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('adminhtml/*/index');
return $resultRedirect;
}
}