3

I'm working on an extension for Magento 2 and can't seem to find any information on how to route a url with an underscore to my controller.

The url I'm trying to go to:

foobar/module/abandoned_carts

Class namespace and name:

namespace Foobar\Service\Controller\Module;
class AbandonedCarts extends \Magento\Framework\App\Action\Action {

I get a 404 when going to the page. I've tried a couple variations on the class name, but can't get it to work. Any suggestions?

Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28

1 Answers1

0

This url will equal to the foobar/module/abandoned/carts so you need create controller 'Index' in the file Foobar\Service\Controller\Module\Abandoned\Carts\Index.php:

namespace Foobar\Service\Controller\Module\Abandoned\Carts;

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

class Index extends Action {
  /**
   * @var PageFactory
   */
  private $_resultPageFactory;

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

  public function execute() {
      return $this->_resultPageFactory->create();
  }
}
maks9889
  • 9
  • 3