Jump to content

Front module controller page Clean URL from BO?


Recommended Posts

Hello, I'm developing a little module and trying to generate a nice URL using:

 

Context::getContext()->link->getModuleLink('mymodule', 'myfrontcontroller');

 

It works but the url I get is different depending on the context, for example if I am on BO I see:

http://www.mysite.com/en/module/mymodule/myfrontcontroller

 

and if I am on a front page I get:

http://www.mysite.com/en/page/mymodule/myfrontcontroller

 

this is the correct one, since it is generated using my custom "SEO and URL settings": "page/{module}/{controller}"

 

I need to get this second SEO friendly link/url from BO because I have to save it in database and send it via mail later.

 

How can I do? any idea?

Edited by misthero (see edit history)
Link to comment
Share on other sites

for now I solved it with a dirt workaround

 

public function moduleFrontUrl($module, $controller){
       $route = Configuration::get('PS_ROUTE_module');
       $route = preg_replace('#\{([^{}]*?module(:[^{}]*)?\}#', $module, $route);
       $route = preg_replace('#\{([^{}]*?controller(:[^{}]*)?\}#', $controller, $route);
       return $route;
   }

 

using it like this

 

$url = $this->moduleFrontUrl('mymodule', 'mycontroller');
// this will return 'page/mymodule/mycontroller' 

 

I get the piece of url I need

 

better solution still needed :ph34r:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...