Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Director::addRules [SOLVED]


Reply

2 Posts   710 Views

Avatar
Lukin

2 August 2012 at 11:49pm (Last edited: 2 August 2012 11:51pm), Community Member, 42 Posts

HI
I need to simulate several urls.

Pages:
1. categories
a. subCategoryA
b. subCategoryB

2. products
a. productTypA
- product1
- product2
b. productTypB
- product 3

I try to simulate a url like this:
categories/subCategoryA/productTypB/product 3

I use this Director::Rule to handle my requests:

Director::addRules(100, array(
'categories//$subCategory!/$productTyp' => 'Hauptkategorie_Controller'
));

and this handler (read the comments):

public static $url_handlers = array(
'' => 'index',
//works ->URL:http://website.xx/categories

'$subCategory' => 'subCategory',
//works ->URL:http://website.xx/categories/subCategory

'$subCategory/$productTyp' => 'test'
// does not work. I'm getting a 404 ->URL:http://website.xx/categories/subCategory/productTyp
);

I think calling the url http://website.xx/categories/subCategory/productTyp does not match the rule, but I don't understand why.

Any help appreciated

Thanks in advance

Lukin

Avatar
Lukin

3 August 2012 at 7:08pm (Last edited: 3 August 2012 7:12pm), Community Member, 42 Posts

This is working ....

Caution! Don't forget the '!'

in my _config
Director::addRules(100, array(
'cateories//$subcategories/$producttyp/$product' => 'Hauptkategorie_Controller'
));

in my handler:
public static $url_handlers = array(
'$subcategories/$producttyp/$product!' => 'test4',
'$subcategories/$producttyp!' => 'test3',
'$subcategories!' => 'test2',
'' => 'test1'
);

cheers ;)