An Adobe Commerce Architect needs to scope a bespoke news section for a merchant's Adobe Commerce storefront. The merchant's SEO agency requests that the following URL structure:
news/{date}/{article_url_key}l where {date} is the publication date of the article, and {article_url_key} is the URL key of the article.
The Architect scopes that a news entity type will be created. The date and URL key data will be stored against each record and autogenerated on save. The values will be able to be manually overridden.
The Architect needs to manage routing this functionality and adhere to best practice.
Which two options should the Architect consider to meet these requirements? (Choose two.)
Correct Answer: A,E
To manage routing this functionality and adhere to best practice, you need to consider the following options:
Create a standard controller route and an Index/Index index controller class that loads the relevant news article by matching the URL date and URL key parts. This option will create a simple and straightforward way to handle the news requests using the standard Magento routing mechanism. The Index/Index controller class will receive the date and URL key parameters from the request and use them to load the news article model from the database.
Create a custom router that runs before the standard router and matches the news portion of the URL, then looks for and loads a news article by matching the date and URL key parts of the URL. This option will create a more flexible and customizable way to handle the news requests using a custom router class that implements \Magento\Framework\App\RouterInterface. The custom router class will check if the request path starts with news, then extract the date and URL key parts from the path and use them to load the news article model from the database.
Reference:
https://belvg.com/blog/how-to-create-custom-router-in-magento-2.html
https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html