Reputation: 4854
I have a module in pyrocms its called event, since I can't call it event due to the already existing events class
I'd like to have the localhost/events url to lead to the event module though, so I've tried setting a route in event/config/routes.php
with this line
$route['events/(:any)?'] = 'event/$1';
but that doesn't work - what am I doing wrong?
Upvotes: 0
Views: 1470
Reputation: 4592
You need to point to class/method ie:
$route['events/(:any)'] = 'class/method/$1';
(:any)
and (:num)
are wildcards. You can use your own patterns.
Take this example(for demonstration purposes):
// www.mysite.com/search/price/1.00-10.00
$route['search/price/(:any)'] = 'search/price/$1';
$1
is equal to the wildcard (:any)
so you could say
public function price($range){
if(preg_match('/(\d.+)-(\d.+)/', $range, $matches)){
//$matches[0] = '1.00-10.00'
//$matches[1] = '1.00'
//$matches[2] = '10.00'
}
//this step is not needed however, we can simply pass our pattern into the route.
//by grouping () our pattern into $1 and $2 we have a much cleaner controller
//Pattern: (\d.+)-(\d.+) says group anything that is a digit and fullstop before/after the hypen( - ) in the segment
}
So now the route becomes
$route['search/price/(\d.+)-(\d.+)'] = 'search/price/$1/$2';
Controller
public function price($start_range, $end_range){}
Upvotes: 6
Reputation: 3408
I think the question mark may interfer with the routing, so it should be:
$route['events/(:any)'] = 'event/$1';
Upvotes: 1