1

I am new enough to Magento and am just trying to create my first module to show all Categories but am having some issues. However I am not sure if it is due to my environment or if there is something else causing the issue.

Below are all my files and their directories. I am using Magento 2.1.11.

When I have these locally (WAMP on windows) I can enable the module and it appears as enabled under 'Stores'->'Configuration'->'Advanced' but I go to http://127.0.0.1/{root}/showCategories and all I can see is an empty page instead of the test echo in showCategories.phtml although I can see in the console that the <body> has a class="showcategories-index-index".

I thought this might just be something weird locally on WAMP but tried uploading it to my live server, however, my company is using shared hosting and I can't run commands like php bin/magento setup:upgrade so went to {root}/app/etc/config.php file and added the line to the array to enable the module, but this seems to just break the whole Magento installation.

Any help or advice with this would be greatly appreciated.

{root}/app/code/{mycompany}/showCategories/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="{mycompany}_showCategories" setup_version="0.0.1" active="true"/>
    </config>

{root}/app/code/{mycompany}/showCategories/composer.json

{
    "name": "{mycompany}/showCategories",
    "description": "showCategories Module",
    "type": "magento2-module",
    "version": "1.0.00"
    "require": {
        "php": ">=5.5.22|~5.6.0|7.0.2|7.0.4|~7.0.6",
        "magento/framework": "100.0.*|100.1.*"
    },
    "repositories": {
        "typ2: "composer",
        "url": "https://repo.magento.com/",
    },
    "minimum-stability": "stable",
    "autoload": {
        "files": [
            "registration.php"
        ],
        psr-4: {
            "{mycompany}\\showCategories\\": ""
        }
    }
}

{root}/app/code/{mycompany}/showCategories/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '{mycompany}_showCategories',
    __DIR__
);
?>

{root}/app/code/{mycompany}/showCategories/Controller/Index/index.php

<?php
namespace {mycompany}\showCategories\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\ResultFactory;

class Index extends Action
{
    public function execute()
    {
        $page = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
        return $page;
    }
}
?>

{root}/app/code/{mycompany}/showCategories/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="showCategories" frontName="showCategories">
            <module name="{mycompany}_showCategories" />
        </route>
    </router>
</config>

{root}/app/code/{mycompany}/showCategories/view/frontend/layout/showCategories_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">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="showCategories_index_index" template="{mycompany}_showCategories::showCategories.phtml">
            </block>
        </referenceContainer>
    </body>
</page>

{root}/app/code/{mycompany}/showCategories/view/frontend/templates/showCategories.phtml

<?php
// test
echo 'showCategories';
?>
Paddy Hallihan
  • 181
  • 1
  • 8
  • may be because you have not defined layout type in you layout file , try adding layout="2columns-left" to <page> tag, you can check this answer for module creation details – Piyush Feb 09 '18 at 11:37
  • @Piyush thanks for your comment, I tried 1 column and two columns but no change in the result – Paddy Hallihan Feb 09 '18 at 11:51
  • @Piyush I tried changing my controller/index/index.php as described in that answer but it resulted in a 404 – Paddy Hallihan Feb 09 '18 at 11:59
  • @PaddyHallihan it can be anything spelling mistake. folder name mistake file permission or any other issue. just compare your module directory with this example https://github.com/kingsatti/HelloWorld_Module_Magento2 – Qaisar Satti Feb 09 '18 at 12:14

0 Answers0