Question

Custom tab added on customer Dashboard but button not linked to my controller and not load my phtml file please check the code below and let me know if i made some mistake. Thanks

Customtab/ImportOrders/Controller/Customer/Index.php

<?php
namespace Customtab\ImportOrders\Controller\Customer;
class Index extends \Magento\Framework\App\Action\Action{
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
 }
}

Customtab/ImportOrders/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">
   <!--Use router 'standard' for frontend route-->
   <router id="standard">
        <!--Define a custom route with id and frontName-->
        <route frontName="importorder" id="import">
            <!--The module which this route match to-->
            <module name="Customtab_ImportOrders"/>
        </route>
       <route id="customer">
           <module name="Customtab_ImportOrders" before="Magento_Customer" />
       </route>
   </router>
</config>

Customtab/ImportOrders/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="Customtab_ImportOrders" setup_version="1.0.0"/>
</config>

Customtab/ImportOrders/view/frontend/layout/customer_account.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>
      <referenceBlock name="customer_account_navigation">
         <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-customer">
            <arguments>
               <argument name="path" xsi:type="string">importorder/customer/index</argument>
               <argument name="label" xsi:type="string">Import Orders</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page>

Customtab/ImportOrders/view/frontend/layout/importorder_customer_index.xml

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

Customtab/ImportOrders/view/frontend/templates/mytab.phtml

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

?>

No correct solution

OTHER TIPS

You need to change controller code

Customtab/ImportOrders/Controller/Customer/Index.php

<?php namespace Customtab\ImportOrders\Controller\Customer;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;
    public function __construct(
      \Magento\Framework\App\Action\Context $context,
      \Magento\Framework\View\Result\PageFactory $pageFactory)
    {
       $this->_pageFactory = $pageFactory;
       return parent::__construct($context);
    }

    public function execute()
    {
        return $this->_pageFactory->create();
    }
 }

Hope this will help you!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top