I have created Custom Module. As it requires some front-end routing, have to create Router.php
Whenever I'm accessing Magento eCommece Frontend other pages, say Category/Product Page. It will call my custom module's Router.php
So how can I limit that this Router.php
, so it will be called only when I access my Custom Module (App\Code\Custom\Module
)
In Addition, Due to this Router.php
, my other custom module pages are not working, which is already working fine before.
I'm using this module as a reference for creating my custom module. https://github.com/tzyganu/Magento2SampleModule/tree/master/Controller
Due to this, my module's other pages are not working. Help needed Urgently.
[UPDATE]
Have issue with app\code\Alphanova\ETrade\etc\frontend\routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="standard">
<route id="mymodule" frontName="mymodule">
<module name="Custom_Module" />
</route>
</router>
</config>
So other pages are working fine now. But now detail page is not working.
http://localhost/magento2/mymodule => Working
http://localhost/magento2/mymodule/test.html => Not Working.
Previous it's working when i have <route id="custom_module" frontName="custom_module">
in routes.xml
app\code\Custom\Module\etc\frontend\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\RouterList">
<arguments>
<argument name="routerList" xsi:type="array">
<item name="Custom_Module" xsi:type="array">
<item name="class" xsi:type="string">Custom\Module\Controller\Router</item>
<item name="disable" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">22</item>
</item>
</argument>
</arguments>
</type>
<virtualType name="CustomModuleRoutingEntityPosts" type="Custom\Module\Model\Routing\Entity">
<arguments>
<argument name="prefixConfigPath" xsi:type="const">Custom\Module\Model\Posts\Url::URL_PREFIX_CONFIG_PATH</argument>
<argument name="suffixConfigPath" xsi:type="const">Custom\Module\Model\Posts\Url::URL_SUFFIX_CONFIG_PATH</argument>
<argument name="factory" xsi:type="object">Custom\Module\Model\PostsFactory</argument>
<argument name="controller" xsi:type="string">posts</argument>
</arguments>
</virtualType>
<type name="Custom\Module\Controller\Router">
<arguments>
<argument name="routingEntities" xsi:type="array">
<item name="posts" xsi:type="object">CustomModuleRoutingEntityPosts</item>
</argument>
</arguments>
</type>
</config>
app\code\Custom\Module\Controller\Posts\View.php
public function execute() {
echo "1111<pre>";
exit;
}
It's not going to controller & gives 404 page error.
[Solved]
It's issue with $request->setModuleName('mymodule');
in Router.php, previously it's $request->setModuleName('custom_module');
Still question is why Product/Catalog routes go to my custom Router.php
? How can i set that Router.php
file only called for some Module & Controller otherwise not. Because we have configuration in di.xml
so that's why it's calling