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.

Blog Module /

Discuss the Blog Module.

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

Adding blog image to blog module in silverstripe 3.1

Go to End

2 Posts   1511 Views


Community Member, 21 Posts

5 June 2013 at 2:33am

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

class BlogEntryDecorator extends DataExtension {

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

   public function updateCMSFields(FieldList $fields) { 
      $fields->addFieldToTab("Root.Main", $BlogImage = new UploadField('BlogImage'), 'Content'); 


# 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

    - BlogEntryDecorator

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

Matty Balaam

Community Member, 74 Posts

9 June 2013 at 7:56am

Edited: 09/06/2013 8:02am

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.