Strange problem with pretty urls in module

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Strange problem with pretty urls in module

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Strange problem with pretty urls in module

Post 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.

...
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: Strange problem with pretty urls in module

Post by cve »

Thanks for your reply but the returnid is present in the url, the value of that is "57"
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Strange problem with pretty urls in module

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: Strange problem with pretty urls in module

Post by cve »

Ok, the problem is my fault. But is there a way to prevent showing returnid param in the pretty url in cmsms?
Post Reply

Return to “Developers Discussion”