1

It's quite straight forward to check if a request url exists in a store scope via url_rewrites.

However, I'm wondering if there is a way to check if a custom route exists (as they don't have an entry in url_rewrites).

I.e. if I have

<?php

class \MyCompany\MyModule\Controller\Index\All extends \Magento\Framework\App\Action\Action

and declared my frontend route

<route id="mymodule" frontName="mymodule">

How to check if mymodule/index/all is a valid request_path (obviously we can try to request this path and will get a HTTP 200 response but I'm trying to avoid going down that path).

3
  • 1
    Just trying to save you some time. I went down this route(no pun intended) awhile ago and there isn't really any good way to do it. – user3685048 Aug 31 '20 at 18:08
  • Thank you, appreciate that. – Alvin Nguyen Aug 31 '20 at 22:41
  • 1
    Check out matchAction method in vendor \Magento\Framework\App\Router\Base. That will return an actionInstance if it is found. For 200 status code, i think, you can try to call execute method from the instance and validate result (depends on response type). – Kharidas Chebotaryov Sep 2 '20 at 11:13

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.