Jump to:

22993 Posts in 11595 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » DataObjectDecorator for Page_Controller init()?

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: 2151 Views
  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    DataObjectDecorator for Page_Controller init()? Link to this post

    how can i use dataobjectdecorator to override a Page_Controller's init method?

    I'm trying this, but it isnt overriding init.. (it will override index() though)

    class PodcastController extends DataObjectDecorator {

       public function init(){
          Debug::dump('testing init call');
       }
    }

    _config.php:
    ...
    DataObject::add_extension('Page_Controller', 'PodcastController');
    ...

    thanks alot,
    -Chris

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: DataObjectDecorator for Page_Controller init()? Link to this post

    I think what you may need to do is extend from Extension, not DataObjectDecorator. Also, I notice you've called it a PodcastController. Semantically speaking, this doesn't make sense. It would probably be something more like PodcastPageExtension.

    Try defining onBeforeInit() or onBeforeInit() on your extension class that is applied to Page_Controller.

    I think onBeforeInit() and onAfterInit() are only in 2.4. However, you could apply this patch if using SS 2.3: http://open.silverstripe.org/changeset/78035/modules/sapphire/trunk/core/control/Controller.php

    In your _config.php, do the following instead as well:

    Object::add_extension('Page_Controller', 'PodcastController');

    Just out of interest, what are you trying to achieve with the extension to Page_Controller?

    Sean

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: DataObjectDecorator for Page_Controller init()? Link to this post

    Hi Sean,
    thanks for your answer.

    out of curiosity, is there anything wrong with overriding index() instead of init()?

    what i am doing is building a podcast module which essentially contains a dataobject that holds information for each episode, and gets attached to pages through a many_many relationship table. i considered making a podcast page, but i wanted to investigate extending pre-existing classes and overriding init() to add the podcast rss feed so itunes users can subscribe.

    thanks again,
    -Chris

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