Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Default action for page_controller

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

Page: 1
Go to End
Author Topic: 417 Views
  • dangerdan
    Avatar
    Community Member
    3 Posts

    Default action for page_controller Link to this post

    Not 100% this is on the right board but here goes...

    I've set up an 'Articles' dataobject to contain articles that are either whitepapers, news articles or blog posts. I've set up an 'ArticlesHome' page for acting as the home page for the various sections of articles (whitepapers/news/blog), and I've set up an action in this page's controller called 'read'.

    On my site, visiting site.com/news/read/article-name/ serves up my article fine, but idealy I would like my URL's to simply be /news/article-name/ or /blog/article-name, without the read method/action in there. Seeing as this page class will serve no other purpose than to 'read' articles is there any way I can set my ArticlesHome_Controller to have a default action, which when passed a parameter simply either serves that page, or throws a 404 if the parameter doesnt exist.

    I've looked at routes, but couldnt figure out how to apply them to what I want to do above, and I looked at overriding the init() method but I'm guessing that isn't going to solve my problem either.

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Default action for page_controller Link to this post

    index() is the default action name for controller. init() is run on every action.

  • dangerdan
    Avatar
    Community Member
    3 Posts

    Re: Default action for page_controller Link to this post

    okay so obviously i can't use that as that is i still want to use that for the index. how then can i go about achieving what i want to achieve?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Default action for page_controller Link to this post

    Ah, well I think the way to remove action entirely is to override the handleAction method on your controller (https://github.com/silverstripe/sapphire/blob/3.0/control/Controller.php#L185).

  • dangerdan
    Avatar
    Community Member
    3 Posts

    Re: Default action for page_controller Link to this post

    I tried to over-ride way this morning, though I seemingly hit a wall as the fields in the request object are protected, and couldnt figure out a way around changing them. Is there no other simpler way to achieve what I want? Or is it just not the case with data objects?

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