Skip to main content
added 101 characters in body
Source Link
Konrad Siamro
  • 1.5k
  • 1
  • 17
  • 29

After go to url http://magento2test.localhost/checkorder/ and http:// and magento2test.localhost/checkorder/index/index/

Module is enabled and visible in Admin Advanced tab

Here is structure of my module: image

After go to url http://localhost/checkorder/ and http://localhost/checkorder/index/index/

Module is enabled and visible in Admin Advanced tab

After go to url magento2test.localhost/checkorder/ and magento2test.localhost/checkorder/index/index/

Module is enabled and visible in Admin Advanced tab

Here is structure of my module: image

Here are my files: registration.php:registration.php:

controller:controller:

Ofc IOf course I tried also with:

etc/module.xmletc/module.xml

etc/frontend/routes.xmletc/frontend/routes.xml

view/frontend/layout/checkorder_index_index.xmlview/frontend/layout/checkorder_index_index.xml

block test.phpblock test.php

I got 404 all the time.
  Ofc IOf course I tried :

  • php bin/magento setup:upgradephp bin/magento setup:upgrade
  • rm -rf var/cache/* var/page_cache/* var/generation/*
    also:rm -rf var/cache/* var/page_cache/* var/generation/*
  • php bin/magento cache:clean / flushphp bin/magento cache:clean / flush
  • php bin/magento indexer:reindexphp bin/magento indexer:reindex
  • php bin/magento setup:di:compilephp bin/magento setup:di:compile

Here are my files: registration.php:

controller:

Ofc I tried also with:

etc/module.xml

etc/frontend/routes.xml

view/frontend/layout/checkorder_index_index.xml

block test.php

I got 404 all the time.
  Ofc I tried :

  • php bin/magento setup:upgrade
  • rm -rf var/cache/* var/page_cache/* var/generation/*
    also:
  • php bin/magento cache:clean / flush
  • php bin/magento indexer:reindex
  • php bin/magento setup:di:compile

Here are my files: registration.php:

controller:

Of course I tried also with:

etc/module.xml

etc/frontend/routes.xml

view/frontend/layout/checkorder_index_index.xml

block test.php

I got 404 all the time. Of course I tried :

  • php bin/magento setup:upgrade
  • rm -rf var/cache/* var/page_cache/* var/generation/*
  • php bin/magento cache:clean / flush
  • php bin/magento indexer:reindex
  • php bin/magento setup:di:compile
Source Link
Konrad Siamro
  • 1.5k
  • 1
  • 17
  • 29

Magento2 controllers doesnt work

I would like to create own controller with own frontend view.

Here are my files: registration.php:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Unity_CheckOrder',
    __DIR__
);

controller:

namespace Unity\CheckOrder\Controller\Index;

//use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{
//    protected $_resultPageFactory;
//
//    public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
//    {
//        $this->_resultPageFactory = $resultPageFactory;
//        parent::__construct($context);
//    }

    public function execute()
    {
        echo '<p>You Did It!</p>';
        var_dump(__METHOD__);
       // $resultPage = $this->_resultPageFactory->create();
       // $resultPage->addHandle('check_order');
      //  return $resultPage;
    }
}

Ofc I tried also with:

namespace Unity\CheckOrder\Controller\Index;

use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $_resultPageFactory;

    public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
    {
        $this->_resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    public function execute()
    {
//        echo '<p>You Did It!</p>';
//        var_dump(__METHOD__);
        $resultPage = $this->_resultPageFactory->create();
        $resultPage->addHandle('check_order');
        return $resultPage;
    }
}

etc/module.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Unity_CheckOrder" setup_version="1.0.0">
    </module>
</config>

etc/frontend/routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="checkorder" frontName="checkorder">
            <module name="Unity_CheckOrder" />
        </route>
    </router>
</config>

view/frontend/layout/checkorder_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="1column">
    <head>
        <title>
            Simple Magento 2 Module
        </title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Unity\CheckOrder\Block\Test" name="checkorder" template="Unity_CheckOrder::checkorder.phtml" cacheable="false"/>
        </referenceContainer>
    </body>
</page>

view/frontend/templates/checkorder.phtml

<?php $this->getHelloWorldTxt(); ?>

block test.php

<?php
namespace Unity\CheckOrder\Block;

class Test extends \Magento\Framework\View\Element\Template
{
    public function __construct(\Magento\Backend\Block\Template\Context $context, array $data = [])
    {
        parent::__construct($context, $data);
    }

    public function getHelloWorld()
    {
        return 'Hello World';
    }
}

I also tried with

<?php
namespace Unity\CheckOrder\Block;

class Test extends \Magento\Framework\View\Element\Template
{
    public function getHelloWorld()
    {
        return 'Hello World';
    }
}

After go to url http://localhost/checkorder/ and http://localhost/checkorder/index/index/

I got 404 all the time.
Ofc I tried :

  • php bin/magento setup:upgrade
  • rm -rf var/cache/* var/page_cache/* var/generation/*
    also:
  • php bin/magento cache:clean / flush
  • php bin/magento indexer:reindex
  • php bin/magento setup:di:compile

Module is enabled and visible in Admin Advanced tab