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.

All other Modules

Discuss all other Modules here.

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

move function from page controller to module


Reply

2 Posts   297 Views

Avatar
badjedi

10 October 2013 at 3:51pm Community Member, 25 Posts

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

10 October 2013 at 3:59pm Community Member, 25 Posts

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);
      }

}