Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Covert DataObject to page

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

Page: 1
Go to End
Author Topic: 980 Views
  • maryfran
    Avatar
    Community Member
    12 Posts

    Covert DataObject to page Link to this post

    I was wondering if it is possible to import the data from a dataobject and change it to a page?

    My client decided that they wanted a full page as opposed to a javascript pop up for each of their products.

    Is there an easy way to do this, or do I need to re-enter everything?

    Any advice is appreciated!

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Covert DataObject to page Link to this post

    It would be pretty trivial to write a little migration task which did something like

    // mysite/code/PageMigrationTask

    <?php
    class PageMigrationTask extends MigrationTask {

    function run() {

    // go through each object making a new page
    $objects = DataObject::get('MyObject');
    foreach($objects as $object) {

    $page = new Page();
    $page->Title = $object->Title;
    $page->ParentID = $ID of page you want these to be under
    $page->writeToStage('Stage');
    $page->publish('Stage', 'Live');
    }
    }
    }

    Then you can run the migration task when you want by going site.com/dev/tasks/PageMigrationTask

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