I want to get block Magento\Catalog\Block\Product\ProductList\Toolbar
, I tried this code but it not work and show error
Type Error occurred when creating the object: `Vendor/Module/Block/Search`
My code
$resultPage = $this->layoutFactory->create();
$blockToolbar = $resultPage->getLayout()->createBlock('Magento\Catalog\Block\Product\ProductList\Toolbar');
var_dump($blockToolbar->getCurrentOrder());
exit;
I tried " Code phtml " in phtml file, it works
Code phtml
$blockToolbar = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ProductList\Toolbar');
var_dump($blockToolbar->getCurrentOrder());exit;
UPDATE
I used $objectManager
and it works
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$blockToolbar = $objectManager->create('Magento\Catalog\Block\Product\ProductList\Toolbar');
var_dump($blockToolbar->getCurrentOrder());
exit;