1

I've got a university project to create a site using a framework given to us by the teacher. I've hosted the site at http://daniel-lucas.com so you can see what's happening.

As you can see the address ends with /?index.

In the configuration file I've just used :

new UrlMapping('^index/$', 'musiconlineapp.listeners.MainListener.handle', 'musiconlineapp/views/MainView.php') 

The first parameter is the address to map. The second is the controller for the page and the method to load in the controller (handle). The third is the view to display for the page.

However I'm having trouble displaying categories for the site. I was told to use mapping like this:

new UrlMapping('^category/(?P<cat>\w+)/$', 'musiconlineapp.listeners.CategoryTitleListener.handle', 'musiconlineapp/views/CategoryTitleView.php' ) 

My problem is that I've not done any regex for a while and can't figure out what address I'm supposed to go to when I click on the link. I've tried /?category&cat=rock and similar variations but none of them work.

1
  • Which framework are you using? Commented Jan 29, 2012 at 11:30

1 Answer 1

3

That regex looks like it's supposed to match /?category/rock/ or the like.

^ # beginning of string category/ # literal 'category/' (?P<cat> # named matching group (named 'cat') \w+ # one or more word characters a-zA-Z0-9_ ) # end the named matching group / # literal '/' $ # end of string 
Sign up to request clarification or add additional context in comments.

2 Comments

Great, thanks. Couldn't figure that one out. What does the ?P do?
(?P<a>b) is how you defined a named matching group that is named a and matches the pattern b

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.