Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » move function from page controller to module

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 266 Views
  • badjedi
    Avatar
    Community Member
    25 Posts

    move function from page controller to module Link to this post

    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.

  • badjedi
    Avatar
    Community Member
    25 Posts

    Re: move function from page controller to module Link to this post

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

    }

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