I call controller function from phtml via ajax, it calls controller function Now i am trying to call block function in controller it is not working
Controller code
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $resultPageFactory,
\Magento\Framework\Registry $registry,
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->_registry = $registry;
$this->_resultLayoutFactory = $resultLayoutFactory;
}
public function execute()
{
if($this->getRequest()->isAjax()){
$start = $_POST['start'];
$end = $_POST['end'];
$enddate = date('Y-m-d 23:55:55', strtotime($end));
$startdate = date('Y-m-d 00:00:00', strtotime($start));
$resultLayout = $this->_resultLayoutFactory->create();
$response = $resultLayout->getLayout()->getBlock('My\Module\Block\dashboard')->getprocesseddata();
return $response;
}
}
In block
public function __construct(
Template\Context $context,
CardsManageFactory $cardsManageFactory,
Data $helperData,
array $data = [],
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Backend\Model\Session $session,
\Magento\Framework\Registry $registry
)
{
$this->_orderCollectionFactory = $orderCollectionFactory;
$this->_categoryFactory = $categoryFactory;
parent::__construct($context, $data);
$this->_cardsManageFactory = $cardsManageFactory;
$this->_helperData = $helperData;
$this->scopeConfig = $scopeConfig; // get api_key and secret_key
$this->session = $session;
$this->_registry = $registry;
}
public function getprocesseddata()
{
return 1;
}
while call controller execute from ajax . call is working. but from controller i cant call block