Answer the question
In order to leave comments, you need to log in
What is wrong with creating a module?
I'm trying to make a simple first module for Magento2. I do everything according to the guide. I
even checked everything 4 times - everything seems to be correct, but the module does not work, when you click on the say/index/index snares, a page with text should open, but the result is an empty page without errors!
I do everything like this: I
create a config for the module:app/Dev/Say/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<module name="Dev_Say" setup_version="1.0.0">
</module>
</config>
app/Dev/Say создаю registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Dev_Say',
__DIR__
);
app/Dev/Say/etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="say" frontName="say">
<module name="Dev_Say"/>
</route>
</router>
</config>
app/Dev/Say/Controller/Index/index.php
<?php
namespace Dev\Say\Controller\Index;
use Magento\Framework\App\Action\Action;
class Index extends Action
{
public function execute()
{
$this->_view->getLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
}
app/Dev/Say/view/frontend/layout/say_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Dev\Say\Block\Say" name="lofformbuilder-toplinks" template="Dev_Say::say.phtml"/>
</referenceContainer>
</body>
</page>
app/Dev/Say/Block/Say.php
<?php
namespace Dev\Say\Block;
use Magento\Framework\View\Element\Template;
class Say extends Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
}
app/Dev/Say/view/frontend/templates/say.phtml
<?php
echo 'Say template';
php bin/magento setup:upgrade
say/index/index
it, there are no errors, just a blank page. Answer the question
In order to leave comments, you need to log in
I don't know if it's still relevant? Anyway.
First, enable developer mode. This will make it possible to see errors right on the page.
Secondly, you write app/Dev....
when it should be app/code/Dev....
.
Thirdly, the module is enabled like this: php -f bin/magento module:enable MyVendor_Module
. Did you turn it on?
By the way, your controller is not complete, look at the guide again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question