wakabayashi Posted November 29, 2023 Posted November 29, 2023 Is it somehow possible to get the controller name and id_entity by throwing an url? I want something like: function getControllerAndId($url) { // Use $url somewow $dispatcher->getController(); } I want to use this in a module... The idea is to recognize posted urls by customers in FrontOffice as product links and replace them. For example: www.domain.ch/category/productXY I want: Controller=ProductController id_product=352
0 datakick Posted November 30, 2023 Posted November 30, 2023 14 hours ago, wakabayashi said: Is it somehow possible to get the controller name and id_entity by throwing an url? I want something like: function getControllerAndId($url) { // Use $url somewow $dispatcher->getController(); } I want to use this in a module... The idea is to recognize posted urls by customers in FrontOffice as product links and replace them. For example: www.domain.ch/category/productXY I want: Controller=ProductController id_product=352 If you are on a bleeding edge, there is a new method Dispatcher::resolveController. We use it in tbshortcodes module for the similar purpose -- to translate internal links to shortcodes. Note that that method has side effects (which I will hopefully fix in the future if I have time) -- it modifies global $_POST and $_GET variables. So when using that method, you should save and restore it later. I'm using it like this: $savePost = $_POST; $saveGet = $_GET; try { $_GET = []; $_POST = []; $controller = strtolower((string)Dispatcher::getInstance()->resolveController($shopId, $requestUri)); $entityId = (int)($_GET['id_' . $controller] ?? 0); // $_GET and $_POST can contain other useful information extracted from request uri } finally { $_GET = $saveGet; $_POST = $savePost; } 1
0 wakabayashi Posted November 30, 2023 Author Posted November 30, 2023 Great! I am not yet on bleeding edge. But this sounds amazing for my purpose! Actually it's also kind of a shortcode usage 🙂
Question
wakabayashi
Is it somehow possible to get the controller name and id_entity by throwing an url?
I want something like:
function getControllerAndId($url) { // Use $url somewow $dispatcher->getController(); }
I want to use this in a module... The idea is to recognize posted urls by customers in FrontOffice as product links and replace them.
For example: www.domain.ch/category/productXY
I want:
2 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now