Page 1 of 1

pretty url in custom module

Posted: Sat Apr 19, 2008 1:20 pm
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.

Re: pretty url in custom module

Posted: Sat Apr 19, 2008 2:53 pm
by Ted
You need a slash after the 1.  You're route is looking for a jobid, then a slash, then a returnid.

Re: pretty url in custom module

Posted: Sat Apr 19, 2008 4:34 pm
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'));

Re: pretty url in custom module

Posted: Sat Apr 19, 2008 4:53 pm
by Ted
Yup, it's just a regex change.

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