I'm hoping for the community's help on a head scratcher.
I'm developing an extension on Magento 2.3.1, and have followed every single guide I've found / including using the magento 2.3 devdocs for inserting a link to the customer account dashboard & having my controller for the link return some test data. My extension is extremely simple and I can inject the link onto the customer account dashboard, but the url injected to my custom controller just 404s. I've tried multiple variations of the guides out there spanning 2.2 to 2.3.0, but none of them result in a non 404 when clicking the link.
I can see my custom link on the Customer Account Dashboard. I can click on the link, which has the correct path for my controller, as defined in customer_account.xml, but when I click on the link... I get a 404 page. Nothing in my system, errors, or debug log related to the 404 at all.
I've cleared cache, I've ensured my module is enabled, I've run setup:upgrade, setup:di:compile, and setup:static-content:deploy. I've ensured my magento2/var and magento2/generated folders (and subfolders) are owned by the proper m2 user.
I've tried naming my Block file something else. I've tried renaming my controller action from Index.php to DoThing.php (and making the expected change to my xml file name / and so-on), I've tried various combinations of a lot of changes that online guides/posts suggest would help, but nothing helps.
I must be missing something incredibly simple. Please see my module structure as defined below. Assume the Company/DoThing folder is in app/code/, eg:
/var/www/html/magento2/app/code/Company/DoThing/
My module is as such:
Base Extension Folder (in app/code/):
Company/DoThing:
registration.php:
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Company_DoThing', __DIR__ );
Block\Index.php
class Index extends \Magento\Framework\View\Element\Template { public function __construct(\Magento\Catalog\Block\Product\Context $context, array $data = []) { parent::__construct($context, $data); } protected function _prepareLayout() { return parent::_prepareLayout(); } }
Controller\Index\Index.php
<?php namespace Company\DoThing\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { public function execute() { $this->_view->loadLayout(); $this->_view->loadLayoutUpdates(); $this->_view->getPage()->getConfig()->getTitle()->set(__('Do The Thing')); $this->_view->renderLayout(); } }
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="Company_DoThing" setup_version="1.0.0"></module> </config>
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"> <router id="standard"> <route id="dothing" frontName="dothing"> <module name="Company_DoThing" /> </route> </router> </config>
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\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-do-thing-link"> <arguments> <argument name="path" xsi:type="string">dothing/index</argument> <argument name="label" translate="true" xsi:type="string">Do The Thing</argument> <argument name="sortOrder" xsi:type="number">123</argument> </arguments> </block> </referenceBlock> </body> </page>
For this one, I've tried
<argument name="path" xsi:type="string">dothing/index/index</argument>
but this also doesn't work.
view\frontend\layout\dothing_index_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"> <update handle="customer_account"/> <body> <referenceContainer name="content"> <block class="Company\DoThing\Block\Index" name="customer.account.do.thing" template="Company_DoThing::dothing.phtml" cacheable="false"/> </referenceContainer> </body> </page>
view\frontend\templates\dothing.phtml
<?php ?> <div class="dothing-account"> <span>testing testing 123</span> </div>
Thanks in advance for any help.