pretty url in custom 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
waxydock
New Member
New Member
Posts: 8
Joined: Fri Apr 18, 2008 12:52 pm

pretty url in custom module

Post by waxydock »

Hi,

Im trying to turn my links in my module into pretty urls, they are working fine in other modules. Ive basically followed the docs found on this site, please tell me if i have done something wrong.

the module is called JobSearch, and im trying to create a friendly link in my action.jobs.php page. I need the link to be directed to my action.job.php page with a jobid parameter.

1. Made a SetParameters function in my JobSearch.module.php file, and created my jobid parameter

Code: Select all

function SetParameters() {
		
		$this->CreateParameter('jobid','','job id', false);
		$this->RegisterRoute('/JobSearch\/(?P<jobid>[0-9]+)\/(?P<returnid>[0-9]+)$/',array('action'=>'job'));
}
2. Used the CreateLink function to generate my pretty url in action.jobs.php

Code: Select all

echo $this->CreateLink($id, 'job', $returnid, '', array('jobid'=>1), '', true, false, '', false, 'JobSearch/1'.$returnid);
currently the result of this echo is: http://www.url.com.au/websites/cmsmades ... rch/1.html but it doesnt work.

Any help is appreciated, thanks.
Last edited by waxydock on Sat Apr 19, 2008 4:35 pm, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: pretty url in custom module

Post by Ted »

You need a slash after the 1.  You're route is looking for a jobid, then a slash, then a returnid.
waxydock
New Member
New Member
Posts: 8
Joined: Fri Apr 18, 2008 12:52 pm

Re: pretty url in custom module

Post by waxydock »

Thanks for that, one more question. How do i allow for the job id to be a string (which can contain numbers, - and letters). Atm it only accepts ints.

Im guessing i need to change the regexp here?

$this->RegisterRoute('/JobSearch\/(?P[0-9]+)\/(?P[0-9]+)$/',array('action'=>'job'));
Last edited by waxydock on Sat Apr 19, 2008 4:38 pm, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: pretty url in custom module

Post by Ted »

Yup, it's just a regex change.

[0-9] would becomes [0-9a-zA-Z\-], I believe.
Post Reply

Return to “Developers Discussion”