10383 Posts in 2197 Topics by 1711 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 226 Views |
-
URL mapping for Module

20 June 2012 at 5:53pm
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
-
Re: URL mapping for Module

20 June 2012 at 7:48pm
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)
-
Re: URL mapping for Module

21 June 2012 at 11:33am
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/ ?
-
Re: URL mapping for Module

21 June 2012 at 6:15pm
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'.
-
Re: URL mapping for Module

22 June 2012 at 11:19am
*head desk*
That showed it was being called correctly, but the controller was incorrectly named...
*sigh*
Works a treat now, strangely...
| 226 Views | ||
|
Page:
1
|
Go to Top |


