1

I am using Magento 2 version 2.2.2

I have a simple custom module and right now for the testing it only has Index controller. The problem is all actions for this Index controller works fine but somehow the action name List is showing "404 Not Found".

Custom module files are as below. At app/code/Vky/ then

enter image description here

Vky/JustTesting/registration.php

<?php

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

Vky/JustTesting/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="Vky_JustTesting" setup_version="1.0.0" />
</config>

Vky/JustTesting/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="justtesting" frontName="justtesting">
            <module name="Vky_JustTesting" />
        </route>
    </router>
</config>

Vky/JustTesting/Controller/Index/Index.php

<?php

namespace Vky\JustTesting\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        echo '<pre>'; print_r("Index Action");die((__FILE__).'-->'.(__FUNCTION__).'--Line('. (__LINE__).')');
    }
}

Vky/JustTesting/Controller/Index/List.php

<?php

namespace Vky\JustTesting\Controller\Index;

class List extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        echo '<pre>'; print_r("List Action");die((__FILE__).'-->'.(__FUNCTION__).'--Line('. (__LINE__).')');
    }
}

At frontend.

http://127.0.0.1/magento222/justtesting/index/index - Works http://127.0.0.1/magento222/justtesting/index/list - Not working

To make sure I created other actions also like View,Save, Delete

http://127.0.0.1/magento222/justtesting/index/view - Works http://127.0.0.1/magento222/justtesting/index/save - Works http://127.0.0.1/magento222/justtesting/index/delete - Works

Then I thought Let me try with List01.php

Vky/JustTesting/Controller/Index/List01.php

<?php

namespace Vky\JustTesting\Controller\Index;

class List01 extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        echo '<pre>'; print_r("List01 Action");die((__FILE__).'-->'.(__FUNCTION__).'--Line('. (__LINE__).')');
    }
}

And http://127.0.0.1/magento222/justtesting/index/list01 - Works

I have tried all this.

php bin/magento setup:upgrade

php bin/magento cache:clean

php bin/magento cache:flush

remove var/cache and var/page_cache folder. But nothing is helping.

Why is the list action not working? Is there any restriction to use action name? Am I missing something? Something wrong with my project? But I have tried this in another project also and the same problem.

If it's because of this.

There is some reserved word in PHP. List is one of them. http://www.php.net/manual/en/reserved.keywords.php Then why I can use it in Magento 1. http://127.0.0.1/magento1936/justtesting/index/list - Works in Magento 1.

I am just hoping for some explanation.

1

There are some reserved word in PHP. List is one of them. http://www.php.net/manual/en/reserved.keywords.php

You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.

  • Maybe. But Then Why I can use it in Magento 1. For example, http://127.0.0.1/magento1936/justtesting/index/list is working at Magento 1. – Vky Jul 7 '18 at 18:27
  • 1
    It works in Magento 1 because the functions of controllers ending with the word Action and the name of the class is something like this Vky_JustTesting_IndexController – raumatbel Jul 7 '18 at 18:37
  • Yes, my friend. It makes sense now. – Vky Jul 7 '18 at 18:53
  • If you think that my answer is the correct. Please, mark it as valid – raumatbel Jul 7 '18 at 18:55
  • Yes, it is valid. I was just trying to make the same for "New" and "Break". Both are reserved word. So It won't work. "New01" and "Break01" Works. Thank you for your help. – Vky Jul 7 '18 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.