1

I am trying to create new tab in customer dashboard.I have added customer_account.xml in my module(Singh/Module1)layout

<body>
    <referenceBlock name="customer_account_navigation">
        <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-about-me">
            <arguments>
                <argument name="path" xsi:type="string">aboutme/customer/index</argument>
                <argument name="label" xsi:type="string" translate="true">About Me</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

frontName : aboutme;

My Controller directory structure: Singh/Module1/Controller/Customer/Index.php.

I have created aboutme_customer_index.xml also

<update handle="customer_account"/>
<body>
    <referenceContainer name="content">
        <block class="Magento\Customer\Block\Account\Dashboard" name="customer.account.link.back" template="account/link/back.phtml" cacheable="false"/>
    </referenceContainer>
</body>

Below is the index.php

class Index extends \Magento\Framework\App\Action\Action //implements AboutmeInterface
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    /**
     * @param Context $context
     * @param PageFactory $resultPageFactory
     */
    public function __construct(
    Context $context,
    PageFactory $resultPageFactory
    ) {
    $this->resultPageFactory = $resultPageFactory;
    parent::__construct($context);
    }

    /**
     * Customer order history
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
    /** @var \Magento\Framework\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->set(__('About Me'));

    $block = $resultPage->getLayout()->getBlock('customer.account.link.back');
    if ($block) {
        $block->setRefererUrl($this->_redirect->getRefererUrl());
    }
    return $resultPage;
    }
}

Below is my route file

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
    <route id="aboutme" frontName="aboutme">
        <module name="Singh_Module1" />
    </route>
</router>

My new tab is coming in Customer account dashboard but it always redirect to 404 not found error.

8
  • plz show your index.php controller file and also routes.xml file to check more Jun 14, 2016 at 8:49
  • I tried by applying die in execute() method; but the control is not coming to there Jun 14, 2016 at 10:03
  • please refer this link magento.stackexchange.com/questions/108421/… Hope help you
    – Vishal
    Jun 14, 2016 at 14:03
  • can you show folder tree structure of your module ? Jun 14, 2016 at 14:04
  • I got the output. I tried by myself and got the output. Thank you all Jun 15, 2016 at 7:31

1 Answer 1

1

Please replace the your controller code with this:

namespace Singh\Module1\Controller\Customer;
class Index extends \Magento\Framework\App\Action\Action //implements AboutmeInterface
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    /**
     * @param Context $context
     * @param PageFactory $resultPageFactory
     */
    public function __construct(
    Context $context,
    PageFactory $resultPageFactory
    ) {
    $this->resultPageFactory = $resultPageFactory;
    parent::__construct($context);
    }

    /**
     * Customer order history
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
    /** @var \Magento\Framework\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->set(__('About Me'));

    $block = $resultPage->getLayout()->getBlock('customer.account.link.back');
    if ($block) {
        $block->setRefererUrl($this->_redirect->getRefererUrl());
    }
    return $resultPage;
    }
}

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