M
M
Maybe_V2016-08-01 12:37:53
PHP
Maybe_V, 2016-08-01 12:37:53

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>

At the root of a module app/Dev/Say создаю registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Dev_Say',
    __DIR__
);

Then I make a router for the frontendapp/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>

I'm making a controller 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();
    }
}

My layout
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>

I create a blockapp/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();
    }

}

And the template itselfapp/Dev/Say/view/frontend/templates/say.phtml
<?php
    echo 'Say template';

Then I register the module and do it php bin/magento setup:upgrade
When I open say/index/indexit, there are no errors, just a blank page.
What could be my mistake? Perhaps I missed something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2016-12-21
@springimport

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 question

Ask a Question

731 491 924 answers to any question