Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Adding blog image to blog module in silverstripe 3.1

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 777 Views
  • nmshah
    Avatar
    Community Member
    21 Posts

    Adding blog image to blog module in silverstripe 3.1 Link to this post

    I am trying to add image to blogs in silvertstripe 3.1 with the help of the following code:

    <?php
    class BlogEntryDecorator extends DataExtension {

    static $has_one = array(
    'BlogImage' => 'Image'
    );

    public function updateCMSFields(FieldList $fields) {
    parent::updateCMSFields($fields);
    $fields->addFieldToTab("Root.Main", $BlogImage = new UploadField('BlogImage'), 'Content');
    $BlogImage->getValidator()->setAllowedExtensions(File::$app_categories['image']);
    }

    }
    ?>

    <?php
    #-------------------------------------------------------------
    # Edit file: mysite/code/_config.php
    #-------------------------------------------------------------
    Object::add_extension('BlogEntry', 'BlogEntryDecorator');
    ?>

    When I try to build database again, I get an error.

    On further research I realized Object::add_extension is deprecated and I have to use something like the following

    BlogEntry:
    extensions:
    - BlogEntryDecorator

    I am not sure about the above code & which file should I put the same in.
    Kindly suggest

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: Adding blog image to blog module in silverstripe 3.1 Link to this post

    You need to put the new code into a file called config.yml.

    If you have the existing code in your mysite folder, this should be located in a folder in mysite called _config

    Another way you could do this would be to create a mini-module.

    File structure would be:

    your-site-root {top level folder}

    BlogEntryDecorator {second level folder}

    _config.php {third level file}

    _config {third level folder}
    config.yml {forth level file}

    code {third level folder}
    BlogEntryDecorator.php {forth level file}

    The advantage of using the second method is that you can then copy that folder easily into another site.

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