3

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

asked Jan 22, 2020 at 10:08
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. Commented Jan 22, 2020 at 10:26
  • i added more information Commented Jan 22, 2020 at 10:43
  • The error may be in your ui_component Can you please update the code here? Commented Jan 22, 2020 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. Commented Jan 22, 2020 at 10:55
  • it was a typing mistake. Commented Jan 22, 2020 at 11:18

5 Answers 5

2

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.

answered Jan 22, 2020 at 11:58
1
  • Helped @keval Kadiya Commented May 17, 2023 at 16:20
2

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

answered Jan 23, 2020 at 8:37
1
  • where did you find that? Commented Jun 30, 2020 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.

answered Jan 22, 2020 at 10:14
1
  • I have max_input_vars = 100000 Commented Jan 22, 2020 at 10:23
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

answered Jan 22, 2020 at 12:12
-1

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 .

answered Jan 22, 2020 at 11:13
3
  • Do I have to do something after writing this code? or will it work directly? Commented Jan 22, 2020 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 Commented Jan 22, 2020 at 11:33
  • i added the exit Commented Jan 22, 2020 at 11:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.