Page 1 of 1

Strange problem with pretty urls in module

Posted: Tue Apr 09, 2013 9:18 am
by cve
Hi, I'm working on module, which purpose is manage recipes. I want to use pretty url's of course. For showing detail of recipe I want to use the url looks like "/recipe/the-title-of-recipe". My question is how to achieve this kind of url in my module? I'm research the knowledge of that in News module, and I saw that:

Code: Select all

$route = new CmsRoute('/[nN]ews\/(?P<articleid>[0-9]+)\/(?P<returnid>[0-9]+)\/(?P<junk>.*?)\/d,(?P<detailtemplate>.*?)$/',
			  $this->GetName());
    cms_route_manager::add_static($route);
So I decided do it in my module like that:

Code: Select all

$route = new CmsRoute('/recipe\/(?P<recipeurl>.*?)\/(?P<returnid>[0-9]+)$/', $this->GetName());
        cms_route_manager::add_static($route);
It works fine, and for getting url like this:

Code: Select all

/recipe/the-title-of-recipe/57
I'm using this code

Code: Select all

$this->CreateLink($id, 'recipe_view', $returnid, '', array('recipe_id' => $recipe['id']), '', true, false, '', true, 'recipe/'.$recipe['url'].'/'.$returnid);
I think, this is very similar with method used in News module, but not works properly.

When I open this url it shows only this action content without template, but news module shows action content with template.

What is wrong?

Re: Strange problem with pretty urls in module

Posted: Tue Apr 09, 2013 5:56 pm
by calguy1000
CMSMS Needs to somehow know the page id (or the returnid) (and therefore the page template) to display. That's why the code below includes a <returnid> in the regular expression.

If you do not have a returnid in the route, then you have to get one from somewhere. Usually this is done with a preference in the modules admin console, with a fallback to the 'default' page id.

...

Re: Strange problem with pretty urls in module

Posted: Tue Apr 09, 2013 6:41 pm
by cve
Thanks for your reply but the returnid is present in the url, the value of that is "57"

Re: Strange problem with pretty urls in module

Posted: Tue Apr 09, 2013 7:03 pm
by calguy1000
Then the problem is probably with the regular expression. .*? will probably match any character, including a / ... so you will either need to re-order the regular expression to put the integer values first, or play with the .*? stuff. I am no regex god.

Re: Strange problem with pretty urls in module

Posted: Tue Apr 09, 2013 7:56 pm
by cve
Ok, the problem is my fault. But is there a way to prevent showing returnid param in the pretty url in cmsms?