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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Probably one letter mistake or something else


Go to End


3 Posts   1194 Views

Avatar
sebastiankozub

Community Member, 59 Posts

24 September 2015 at 7:00am

I use a pattern that I used to use many times, but when I click "Save" or "Save & Publish" images disappear from upload filed (like loosing linking between photo and page).

<?php

class AboutUsPage extends Page 
{    
    private static $allowed_children = false;
        
    public static $has_many = array(
        'AboutUsPhotos' => 'AboutUsPhoto'
    );
    
    public function getCMSFields() 
    {
        $fields = parent::getCMSFields();
             
        $fields->addFieldToTab('Root', new Tab('AboutUsPhotosTab', _t('AboutUsPage.AboutUsPhotosTab', 'Zdjęcia')));
        
        $fields->addFieldToTab('Root.AboutUsPhotosTab', $uploadFieldForPhotos = new UploadField("AboutUsPhotoPhotos", _t("AboutUsPage.AboutUsPhotosTab", "Zdjęcia")));   
        $uploadFieldForPhotos->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
        $uploadFieldForPhotos->setAllowedMaxFileNumber(3);        

        return $fields;
    }
}

class AboutUsPage_Controller extends Page_Controller 
{

}

class AboutUsPhoto extends Image
{
    public static $has_one = array(
            'AboutUsPage' => 'AboutUsPage'
    );
}

?>

Avatar
Vix

Community Member, 60 Posts

29 September 2015 at 9:49pm

Have you tried using a gridfield for the 'AboutUsPhotos'? eg

$fields->addFieldToTab('Root.AboutUsPhotosTab', new GridField('AboutUsPhotos', 'AboutUsPhoto', $this->AboutUsPhotos())); 

Avatar
sebastiankozub

Community Member, 59 Posts

2 October 2015 at 2:12am

Here is the mistake

  new UploadField("AboutUsPhotoPhotos",