0

I have a custom module with an admin controller, but when I try to access from the administration page I get the following error:

enter image description here

My controller is in Controller/Adminhtml/Login/Index.php

class Index extends \Magento\Backend\App\Action {...}

and the route decalaration in etc/adminhtml/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="admin">
        <route id="oct" frontName="oct">
            <module name="Oct_Oct" before="Magento_Backend" />
        </route>
    </router>
</config>

the layout is in view\adminhtml\layout\oct_login_index.html

<?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="oct\oct\Block\Adminhtml\Login\Index" name="oct_login_login" template="login.phtml"/>
        </referenceContainer>

    </body>
</page>

when i put the cursor on the adminhtml link get:

https://store.com/administrador55/oct/login/index/key/526f769ae4f621ffbda151c2a48015933d510d2d64fe2047abc29cbc29c27e27/

Debug:

enter image description here

any idea?

Thnks

7
  • Please Check the route that you have defined is it created or not. This error occurs due to wrong route. For example if you have action/url feedback/customer/create then feedback should be your route, customer your controller and create is your action of controller. – Keval Kadia Jan 22 '20 at 10:26
  • i added more information – Miguel Jan 22 '20 at 10:43
  • The error may be in your ui_component Can you please update the code here? – Ranganathan Jan 22 '20 at 10:55
  • Is it a typing mistake or you have named controller folder Cotroller like this? And if its typing mistake share your layout and ui_component xml files. – Keval Kadia Jan 22 '20 at 10:55
  • it was a typing mistake. – Miguel Jan 22 '20 at 11:18
1

Please Replace your oct_login_index.xml with this code

<?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="oct\oct\Block\Adminhtml\Login\Index" name="oct_login_login" template="vendor_module::login.phtml"/>
          </referenceContainer>

    </body>
</page>

In above code i have added vendor_module.You should provide vendor_module to point your file in template where you define your phtml file.

1

I have finally found the solution.

The mistake was that i had the module folder like:

../code/Oct/oct

I changed it for

../code/Oct/Oct

and everything works correctly.

Thank you very much everyone for your help and answers

1
  • where did you find that? – jibin george Jun 30 '20 at 15:55
0

This could be the max_input_vars problem but without seeing more of your code I am not sure.

Set max_input_vars to 10000 in php.ini and restart your web server (or php-fpm) and then give it another go.

1
  • I have max_input_vars = 100000 – Miguel Jan 22 '20 at 10:23
0

You need to debug this to get where the issue is . Open in your local envoirment

vendor/magento/module-backend/App/Action/Plugin/Authentication.php 
vendor/magento/module-backend/App/AbstractAction.php

and add this :

$backtrace = [];
$debugBackTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($debugBackTrace as $item) {
    $backtrace[] = @$item['class'] . @$item['type'] . @$item['function'] . "\n";
}
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/invalid_form_key.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info(__FUNCTION__);
$logger->info($backtrace);
$logger->info('***************************************************************');

Check the result it here /var/log/invalid_form_key.log .

3
  • Do I have to do something after writing this code? or will it work directly? – Miguel Jan 22 '20 at 11:25
  • no just paste the code , this is an example dev\tests\api-functional\framework\Magento\TestFramework\TestCase\Webapi\Adapter\Rest\DocumentationGenerator.php of using debugtrace method. In the moment you replicate the issue with form key , check if the log will be updated – Ylgen Guxholli Jan 22 '20 at 11:33
  • i added the exit – Miguel Jan 22 '20 at 11:43
0

Below solution is worked for me:

app\code\Vendor\Module\etc\adminhtml\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="admin">
        <route id="oct" frontName="oct">
            <module name="Vendor_Module" before="Magento_Backend" />
        </route>
    </router>
</config>

app\code\Vendor\Module\view\adminhtml\layout\oct_login_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="Vendor\Module\Block\Adminhtml\Login\Index" name="oct_login_login" template="Vendor_Module::login.phtml"/>
        </referenceContainer>
    </body>
</page>

Here block class Vendor\Module\Block\Adminhtml\Login\Index should extends Magento\Backend\Block\Template.

app\code\Vendor\Module\Controller\Adminhtml\Login\Index.php

<?php
namespace Vendor\Module\Controller\Adminhtml\Login;

class Index extends \Magento\Backend\App\Action
{
    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $resultPageFactory;

    /**
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    /**
     * @return \Magento\Backend\Model\View\Result\Page
     */
    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->addBreadcrumb(__('Test Page'), __('Test Page'));
        $resultPage->getConfig()->getTitle()->prepend(__('Test Page'));
        return $resultPage;
    }
}

app\code\Vendor\Module\view\adminhtml\templates\login.phtml

Add your content here

Then Final result will be:

Result Screenshot

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.