Pergunta

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__
);
Foi útil?

Solução

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top