main.CRITICAL: Class Company\Modulename\Block\Index does not exist
Frage
I'm creating a very simple module and I am missing something.
The module page will not load, and I see these errors:
[2020-12-11 15:51:21] main.CRITICAL: Class Company\Modulename\Block\Index does not exist [] []
[2020-12-11 15:51:21] main.CRITICAL: Invalid block type: Company\Modulename\Block\Index [] []
I believe the problem must be somewhere in these two files and the name of them
Company/Modulename/view/frontend/layout/mapsearch_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Mapsearch bbb</title>
</head>
<body>
<referenceContainer name="content">
<block class="Company\Modulename\Block\Index" name="mapsearch_index" template="Company_Modulename::mapsearch.phtml" />
</referenceContainer>
</body>
</page>
Company/Modulename/Block/Index/Index.php
namespace Company\Modulename\Block;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
class Index extends Template
{
public function __construct(Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager
)
{
$this->_storeManager = $storeManager;
parent::__construct($context);
}
public function getBaseUrl()
{
return $this->_storeManager->getStore()->getBaseUrl();
}
public function getNeData()
{
return $this->getNe();
}
public function getNwData()
{
return $this->getNw();
}
}
Lösung
There is an error in block structure of this file - Company/Modulename/Block/Index/Index.php
It should be in Company/Modulename/Block/Index.php
Basically, have to remove Index
directory and have to move Index.php
in Company/Modulename/Block/
directory.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange