1

I'm having some trouble with Router.php.

I'm guessing it's the line(s) where I check the URL and return false?

Exception #0 (LogicException): Front controller reached 100 router match iterations

My module is: /Vendor/Realproduct/

I want to allow users to do:
/realproducts/123-test-test1

And have it use: /realproduct/?year=123&make=test&model=test1

<?php
namespace Vendor\Realproduct\Controller;

class Router implements \Magento\Framework\App\RouterInterface
{
    /**
     * @var \Magento\Framework\App\ActionFactory
     */
    protected $actionFactory;

    /**
     * Router constructor.
     *
     * @param \Magento\Framework\App\ActionFactory $actionFactory
     */
    public function __construct(
        \Magento\Framework\App\ActionFactory $actionFactory
    ) {
        $this->actionFactory = $actionFactory;
    }

    /**
     *
     * @param \Magento\Framework\App\RequestInterface $request
     * @return bool
     */
    public function match(\Magento\Framework\App\RequestInterface $request)
    {
        $identifier = trim($request->getPathInfo(), '/');
        $d = explode('/', $identifier, 3);

        if(isset($d[0]) && ($d[0] != 'Realproducts')) {
          return false;
        }


        $paramStr = '';
        if(isset($d[1])) {
          $paramStr = $d[1];
        }

        $params = [];

        if($paramStr) {
          $params = explode('-', $paramStr);
        }


        $params = ['year' => $params[0], 'make' => $params[1], 'model' => $params[2]];

        //print_r($params);
        //exit;

        $request->setModuleName('Realproduct')->setControllerName('index')->setActionName('index');
        if(count($params)) {
          $request->setParams($params);
        }

        $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
        //print_r($request);
        //exit;
        return $this->actionFactory->create(
            'Magento\Framework\App\Action\Forward',
            ['request' => $request]
        );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.