Can i show my custom module in frontend without modifying the RouterDependencyProvider.php file?
Hi Team, I have create a custom module inside src/Pyz/Yves and using that i am showing the homepage. Inside the src/Pyz/Yves/Router/RouterDependencyProvider.php, I have replaced new HomePageRouteProviderPlugin() with my custom module plugin i.e new CustomRouteProviderPlugin() and right now homepage is loading from my custom module.
Now i want to load this homepage without modifying the RouterDependencyProvider.php file.
Is their any way to call this new CustomRouteProviderPlugin() inside my custom module, so that i don't have to modify RouterDependencyProvider.php.
If yes, can you share some example code or any reference code that can help?
Answers
-
Good morning here @sunil!
I believe your are replacing the HomePageRouteProviderPlugin() right?
Rather than that, create a new one in your module (you can copy HomePageRouteProviderPlugin()), refactor it to match your needs and then add a new line in the \Pyz\Yves\Router\RouterDependencyProvider::getRouteProvider referencing your new RouteProviderPlugin().if you check the getRouteProvider function, it has a new function for each controller-managed route (You could also go the StorageRouter, but I guess that's another (more complicated) story :) )
Here's \Pyz\Yves\Router\RouterDependencyProvider::getRouteProvider:protected function getRouteProvider(): array
{
return [
# (... Other route plugins)
new HomePageRouteProviderPlugin(),
# (... Other route plugins)
new MyNewControllerRouteProviderPlugin(),
];
}
0 -
These are the screenshot of my code structure.
Now i want to make this homepage running without modifying RouterDependencyProvider.php file / adding this line new CustomRouteProviderPlugin() in the RouterDependencyProvider.php
Is their any way to add this line inside my custom module, as i want this module to be independent module.
And also can you share some example or reference code.
0 -
Hi @sunil ,
Registering your routes is compulsory action so that application can know which action ( in our case indexAction() )to perform when a new request is received. RouterDependencyProvider basically adds your provided routes in routeCollection. You can't ignore this step if you want your custom url to work. Router in itself is a separate module for manging routing in Spryker, so you should not move it's logic in your custom module.
Reference :-
Thanks0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 927 Developer Corner
- 785 Spryker Development
- 88 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random