I want to add an "id"/"parameter" to a front-end route in the following way:
store.example.com/blogpost/view/**213**
where 213 is the parameter I want to pass.
I have been looking at the Magento 2 dev docs, but I can't seem to find anything regarding adding this parameter.
And I can't seem to find anything that adds the "id" to the existing product route (catalog/product/view/id/:id
) in magento/module-catalog. I'm probably missing something.
etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="blogpost" frontName="blogpost">
<module name="MyModule_BlogPost" />
</route>
</router>
</config>
Controller/View/Index.php
<?php
namespace MyModule\BlogPost\Controller\Search;
class Index extends \Magento\Framework\App\Action\Action
{
public function execute()
{
// This only includes url query parameters ?param1=123¶m2=active
$params = $this->getRequest->getParams();
// But I'd like to do this like the catalog/product/view/id/:id route ...
}
}
Do I need to make a custom router for this, or is there another way?
store.example.com/blogpost/view/213
as a frontend page.