3

I have custom controller outputting JSON format which works well for the below URL level;

** Works
base url/module/folder/action
//equates to Vendor\Module\Controller\Folder\Index.php

However I would like some somewhat deeper nested URL endpoints as per below but I get 404 on controllers deeper that one folder;

**Hit with 404
base url/module/folder/anotherfolder/action
//equates to Vendor\Module\Controller\Folder\Anotherfolder\Index.php

/* or even deeper */

**Hit with 404 - not tested
base url/module/folder/anotherfolder/deeperfolder/action
//equates to Vendor\Module\Controller\Folder\Anotherfolder\Deeperfolder\Index.php

I'm guessing Magento2 doesn't allow deep nested URL types or controllers ...

For me, this deeper nesting would be ideal to have a more manageable controller development & access since we have lost the ability to have multiple actions/endpoints in the one controller (Magento 1.*) (advise if not the case)

2

For this path

Vendor\Module\Controller\Folder\Anotherfolder\Deeperfolder\Index.php

URL will be

url/module/folder_anotherfolder_deeperfolder/action

As per as magento URL format is

URL/frontenName/ACtionFolder/Action

Frontendname is defined at routes.xml

ACtionFolder locates at Controller folder which can multiple folders path but path will connect via (_) Undescore

Action is the php class.
  • ideally I would prefer URL without underscores (underscores changed to forward slashes) but this would need additional rewrites programmatically (and not manually created via admin panel etc) – BENN1TH Sep 15 '18 at 6:18
1

In Magento Catalog module has very nice and simple example by adding any product to compare.

Url Action Is :-

http://127.0.0.1/magento/catalog/product_compare/index/

Your Layout is :-

catalog_product_compare_index.xml

Folder structure is :-

/vendor/magento/module-catalog/Controller/Product/Compare/Index.php

It's very simple, magento has many examples.

Your Answer

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

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