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.

All other Modules /

Discuss all other Modules here.

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

move function from page controller to module


Go to End


2 Posts   1224 Views

Avatar
badjedi

Community Member, 25 Posts

10 October 2013 at 3:51pm

I am moving some code from a site into a module.

I have the following in my Page_controller on Page.php working.

class Page_Controller extends ContentController {
function RandomText($num=1) {
return DataObject::get("TextResource", "", "RAND()", "", $num);
}
}

But when try to move the class in many ways to a module SS can't seem to find it.

in seperate file(module/code/Randomtext_Controller.php) I have:
<?php

class RandomText_Controller extends Page_Controller {
function RandomText($num=1) {
return DataObject::get("TextResource", "", "RAND()", "", $num);
}

}

and tried various things like:

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

in the modules _config.php

Any ideas thanks in advance.

Avatar
badjedi

Community Member, 25 Posts

10 October 2013 at 3:59pm

Just figured it out after more research:
just changed extends Page_controller to extends Extension, so:

<?php

class RandomText_Controller extends Extension {
function RandomText($num=1) {
return DataObject::get("TextResource", "", "RAND()", "", $num);
}

}