I want call block methods from controller. My files are below
Controller
namespace Vendor\ModuleName\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
class Index extends Action
{
public function __construct(Context $context) {
parent::__construct($context);
}
public function execute() {
}
}
Layout
cms_index_index
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="2columns-left">
<head>
</head>
<body>
<referenceContainer name="content">
<block class="Vendor\ModuleName\Block\ProductTabs" name="producttabs" template="producttabs.phtml" ifconfig="form_section/form_group_general/status">
</block>
</referenceContainer>
</body>
</page>
Block
namespace Vendor\ModuleName\Block;
class ProductTabs extends \Magento\Framework\View\Element\Template
{
public function __construct(\Magento\Framework\View\Element\Template\Context $context,array $data = [])
{
parent::__construct($context, $data);
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getMsg(){
return 'i am in block';
}
}
I want getMsg()
to be accessed in controller. If anybody know then please share your experience.