0

It added the Buttton but when i click on it it goes to 404 error.

My Folder Structure be Like

enter image description here

And my code is : index.php

<?php
namespace Demo\Mod\Controller\Index;

use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{

    public function execute()
    {
        $this->_view->loadLayout(); 
        $this->_view->renderLayout(); 
        /*echo 'Hello World 11111  ajjjjjjjjjjjjj';
        exit;*/
    }


}

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="routename" frontName="routename">
            <module name="Demo_Mod" />
        </route>
    </router>
</config>

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="Demo_Mod" setup_version="2.1.1" active="true"/>
</config>

customer_account.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceBlock name="customer_account_navigation">
         <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer- 
   account-navigation-custom">
            <arguments>
               <argument name="path" xsi:type="string">routename/customer/index</argument>
               <argument name="label" xsi:type="string">Setup</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page>

routename_customer_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/e 
    tc/page_configuration.xsd"> 
<update handle="customer_account"/> 
<body> 
    <referenceBlock name="page.main.title"> 
            <action method="setPageTitle"> 
                <argument translate="true" name="title" xsi:type="string">My 
Setup</argument> 
            </action> 
 </referenceBlock> 
 <referenceContainer name="content"> 
    <block class="Magento\Framework\View\Element\Template" name="my_tab" template="Demo_Mod::mytab.phtml"> 
    </block> 
</referenceContainer> 
</body> 
</page>

mytab.phtml

<?php 
 // Add Some Code Here for design
?>
<span> My Setup Custom Tab.. </span>

and last file registration.php

<?php

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

1 Answer 1

1

Try to rename this file name routename_customer_index.xml with routename_index_index.xml.

And in customer_account.xml this file update below content

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceBlock name="customer_account_navigation">
         <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer- 
   account-navigation-custom">
            <arguments>
               <argument name="path" xsi:type="string">routename</argument>
               <argument name="label" xsi:type="string">Setup</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page>

There you added wrong URL routename/customer/index, just use routename there and then clean and flush Magento cache and check.

Or Follow this article

Hope this will help you!

15
  • I have renamed the file it still goes to 404
    – Prits
    Jul 3, 2020 at 5:44
  • 1
    Yupp it works Thanks for that :)
    – Prits
    Jul 3, 2020 at 5:59
  • 1
    @Prits, Because you create controller directory name "Index" and you're using "customer" there, If you want to use customer in url then you have to use Customer as Controller directory name and also in Action file you need to change path then it will work as expected. Jul 3, 2020 at 6:04
  • 1
    thanks for that info.
    – Prits
    Jul 3, 2020 at 12:57
  • 1
    I have asked another question please have a look magento.stackexchange.com/questions/316827/…
    – Prits
    Jul 8, 2020 at 6:01

Your Answer

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

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