21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1773 Views |
-
DataObjectDecorator for Page_Controller init()?

3 December 2009 at 5:02pm
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 -
Re: DataObjectDecorator for Page_Controller init()?

3 December 2009 at 9:17pm Last edited: 3 December 2009 9:22pm
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
-
Re: DataObjectDecorator for Page_Controller init()?

5 December 2009 at 9:35am Last edited: 5 December 2009 9:36am
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
| 1773 Views | ||
|
Page:
1
|
Go to Top |


