Jump to:

10929 Posts in 2613 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » URL mapping for Module

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 392 Views
  • Webko
    Avatar
    Community Member
    3 Posts

    URL mapping for Module Link to this post

    Dear All,

    Let's say I have a module GadgetSearch, with a page type in the CMS. GadgetSearch uses an XML call to gather it's data - there is no relevant database table for the search.

    All is good andworks great, so long as I call /gadgetsearch/ and/or remember to change the MetaData URL entry to read /gadgetsearch/

    But if I create a new page called Gadget Search, then the URL will be automatically /gadget-search/ and this fails. Is there a way to use the CMS or the controller to go to the right place? I know I could edit the config for the module, but the users can't do this...

    Cheers

    T

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: URL mapping for Module Link to this post

    Were have you hard coded the URL? You should use the Link() function rather than hardcoding any page URL. You could also setup a route to point a URL to a given controller (just like googlesitemaps works - https://github.com/silverstripe-labs/silverstripe-googlesitemaps/blob/0.2/_config.php#L4)

  • Webko
    Avatar
    Community Member
    3 Posts

    Re: URL mapping for Module Link to this post

    What I mean is the module lives at /gadgetsearch/

    If an admin user uses the Gadget Search page type to create a new top level page, the navigation will go to wherever they specified in the Page Name by default, ie if they decide to call the page Widget Search, then by default this will go to /widget-search/ on the site from the navigation.

    As I can't tell what they might call the page, how can I make sure a page of the type Gadget Search always ends up in the module folder /gadgetsearch/ ?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: URL mapping for Module Link to this post

    You can't always make sure. I think what you want is when the user goes to a page something happens so you would have a page type setup like

    class GadgetSearchPage extends Page {

    }

    class GadgetSearchPage_Controller extends Page_Controller {

    }

    If you want to perform an operation when the user hits a GadgetSearchPage then you can include something in the init() function of the Controller

    class GadgetSearchPage_Controller extends Page_Controller {

    function init() {
    echo "Hi!";
    }
    }

    Whenever you hit a page type of 'GadgetSearchPage' then it will echo 'hi'. I.e if you create a GadgetSearchPage in the CMS and call it 'hello' then site.com/hello will echo 'hi'.

  • Webko
    Avatar
    Community Member
    3 Posts

    Re: URL mapping for Module Link to this post

    *head desk*

    That showed it was being called correctly, but the controller was incorrectly named...

    *sigh*

    Works a treat now, strangely...

    392 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.