没有找到Silverstripe ImageField

时间:2015-09-20 14:41:34

标签: silverstripe imagefield

我正在尝试扩展Member类并为其添加许多字段。同时我将这个DataObject表现为一个页面,以便我可以访问www.mysite.com/member/show/1并查看该用户的个人资料。我还没有达到创建成员页面的程度。现在我让所有字段都使用ImageField的例外。我收到以下错误:

PHP Fatal error:  Class 'ImageField' not found in ../mysite/code/Secure/Objects/MemberDecorator.php on line 66

代码是:

<?php
class MemberDecorator extends DataExtension {
    private static $db = array(
        "Alias" => 'Varchar',
        "About" => 'Text',
        "Birthday" => 'Date',
        "FavoriteGames" => 'Varchar',
        "Facebook" => 'Varchar',
        "Twitter" => 'Varchar',
        "Instagram" => 'Varchar',
        "Twitch" => 'Varchar',
        "Youtube" => 'Varchar',
        "SecretQuestionOne" => "Varchar",
        "SecretAnswerOne" => "Varchar",
        "SecretQuestionTwo" => "Varchar",
        "SecretAnswerTwo" => "Varchar",
        "SecretQuestionThree" => "Varchar",
        "SecretAnswerThree" => "Varchar"
    );
    private static $has_one = array(
        'Photo' => 'Image'
    );

    //Fields to show in the DOM table
    static $summary_fields = array(
        'Thumb' => 'Photo',
        "Alias" => 'Alias',
        "About" => 'About',
        "Birthday" => 'Birthday',
        "FavoriteGames" => 'FavoriteGames',
        "Facebook" => 'Facebook',
        "Twitter" => 'Twitter',
        "Instagram" => 'Instagram',
        "Twitch" => 'Twitch',
        "Youtube" => 'Youtube',
        "SecretQuestionOne" => "SecretQuestionOne",
        "SecretAnswerOne" => "SecretAnswerOne",
        "SecretQuestionTwo" => "SecretQuestionTwo",
        "SecretAnswerTwo" => "SecretAnswerTwo",
        "SecretQuestionThree" => "SecretQuestionThree",
        "SecretAnswerThree" => "SecretAnswerThree"
    );

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $this->extend('updateCMSFields', $fields);
        return $fields;
    } 

    function updateCMSFields(FieldList $fields) { 
        $fields->push(new TextField("Alias", "Alias"), 'Members');
        $fields->push(new TextAreaField("About", "About"), 'Members');
        $fields->push(new DateField("Birthday", "Birthday"), 'Members');
        $fields->push(new TextField("FavoriteGames", "Favorite Games"), 'Members');
        $fields->push(new TextField("Facebook", "Facebook"), 'Members');
        $fields->push(new TextField("Twitter", "Twitter"), 'Members');
        $fields->push(new TextField("Instagram", "Instagram"), 'Members');
        $fields->push(new TextField("Twitch", "Twitch"), 'Members');
        $fields->push(new TextField("Youtube", "Youtube"), 'Members');
        $fields->push(new TextField("SecretQuestionOne", "Secret Question One"), 'Members');
        $fields->push(new TextField("SecretAnswerOne", "Secret Answer One"), 'Members');
        $fields->push(new TextField("SecretQuestionTwo", "Secret Question Two"), 'Members');
        $fields->push(new TextField("SecretAnswerTwo", "Secret Answer Two"), 'Members');
        $fields->push(new TextField("SecretQuestionThree", "Secret Question Three"), 'Members');
        $fields->push(new TextField("SecretAnswerThree", "Secret Answer Three"), 'Members');
        $fields->push(new ImageField('Photo', 'Photo', Null, Null, Null, 'Uploads/member-photos/'), 'Members');
    }

    function Link() { 
        return Director::absoluteBaseURL() . SSViewer::topLevel()->URLSegment . "/member/" . $this->ID; 
    }

    //Generate our thumbnail for the DOM
    public function getThumb()
    {
        if($this->PhotoID)
            return $this->Photo()->CMSThumbnail();
        else   
            return '(No Image)';
    }
}

根据我发现的每个例子和文档,ImageField似乎是一个有效的字段。最后一点细节是我遵循本指南:http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/

0 个答案:

没有答案