Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

How to extend Controller


Go to End


2828 Views

Avatar
MarijnKampf

Community Member, 176 Posts

30 March 2010 at 5:20am

Edited: 30/03/2010 5:21am

I've been working on an extension that will allow for multiple comment areas on a single page. I've got it working, and most of the functionality is all neatly contained within the extension. However, I've created three functions that are used within the templates, to specify where the comment areas should be defined.

Currently the only way I can get it to work is to define them in the _Controller class of the Page class I'm using in my system:

class Species_Controller extends Page_Controller {
	function PageComments($location = null) {
		:::::: code ::::::
	}
}

works.

If I try to extend the Extension class

class PageCommentMulti_Controller extends Extension {
	function PageComments($location = null) {
		:::::: code ::::::
	}
}

and add that to the controller in the _config.php
Object::add_extension('Species_Controller', 'PageCommentMulti_Controller');

it doesn't work. There are no errors, the functionality just isn't shown in the templates.

Is there a way to extract/abstract the Controller class allowing the functionality to be easily implemented in other systems and for other classes, without having to define the Controller functions manually?