Jump to:

22992 Posts in 11842 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Director::addRules [SOLVED]

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

Page: 1
Go to End
Author Topic: 574 Views
  • Lukin
    Avatar
    Community Member
    41 Posts

    Director::addRules [SOLVED] Link to this post

    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

  • Lukin
    Avatar
    Community Member
    41 Posts

    Re: Director::addRules [SOLVED] Link to this post

    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 ;)

    574 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.