Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Adding extension error

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 341 Views
  • folibis
    Avatar
    Community Member
    10 Posts

    Adding extension error Link to this post

    I am trying to add new field to user profile, or rather image for avatar
    I created new simple file

    class MemberExtension extends DataExtension {
       static $db = array(
    'Avatar' => 'Varchar(200)',
    );

       function updateCMSFields(FieldList $fields) {
          $fields->addFieldToTab("Root.Main", new UploadField('Avatar'));
       }
    }


    and, of course

    Object::add_extension("Member", "MemberExtension");

    into _config.php
    After that my CMS just got crazy.
    I cant enter to Files or any else section. I cant upload image (got some Json error).
    What i do wrong?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Adding extension error Link to this post

    UploadField expects a has_one relationship to the image class.

    @see
    http://doc.silverstripe.org/framework/en/reference/uploadfield

  • folibis
    Avatar
    Community Member
    10 Posts

    Re: Adding extension error Link to this post

    class MemberExtension extends DataExtension {
       static $db = array(
    'Avatar' => 'Varchar(200)',
    );
       static $has_one = array(
    'AvatarImage' => 'Avatar'
    );
       function updateCMSFields(FieldList $fields) {
          $fields->addFieldToTab("Root.Main", new UploadField($name = 'AvatarImage',$title = 'Avatar image'));
       }
    }

    $has_one not helps.
    And by the way there are no php errors in the log.
    Any ideas?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Adding extension error Link to this post

    As I've said, you need a relationship to a image class.

    class MemberExtension extends DataExtension {
       static $has_one = array(
          'Avatar' => 'Image',
       );
       function updateCMSFields(FieldList $fields) {
          $fields->addFieldToTab("Root.Main", new UploadField('Avatar'));
       }
    }

    @see
    http://doc.silverstripe.org/framework/en/reference/uploadfield

    there are no php errors in the log

    You need to set your enviroment to 'dev mode' for proper error messages.
    Director::set_environment_type("dev");

    @see
    http://doc.silverstripe.org/framework/en/topics/debugging

  • folibis
    Avatar
    Community Member
    10 Posts

    Re: Adding extension error Link to this post

    it was to no purpose
    I have Director::set_environment_type("dev"); in my _config.php

    After login to CMS it jumps to Page section. If I press "Files" or eny else section, loader appears for a seccond and nothing happened.
    Button remains pressed.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Adding extension error Link to this post

    I'm sure there is something in your error log. Did you rebuild your database? What version of Silverstripe do you use?

  • folibis
    Avatar
    Community Member
    10 Posts

    Re: Adding extension error Link to this post

    I use 3.0.55
    And yes, i did /dev/build and /dev/build?flush=all too
    my log is empty or, rather, there are no today records

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