Resizing images when loading in Silverstripe ModelAdmin

I'm new to Silverstripe, and it's hard for me to find the answer to my problem in the documentation or in SO.

I use Silverstripe exclusively as a CMS: there is no website as an interface.

I have the simplest DataObject Productand ModelAdmin ProductAdminas follows:

class Product extends DataObject
{

  private static $db = array(
    'Name' => 'Varchar',
    'Copy' => 'Text'
  );

  private static $has_one = array(
    'MyImage' => 'Image'
  );

}


class ProductAdmin extends ModelAdmin
{

  private static $managed_models = array(
    'Product'
  );

  private static $url_segment = 'product';

  private static $menu_title = 'Product';

}

After /dev/buildmy admin panel is built, I can upload a high resolution image to the “Downloads” directory, as usual.

, CMS , . , FlushGeneratedImagesTask . , , , , ( ) . - ?

( , Silverstripe 3.1 - , , , CMS /overridden.)

Silverstripe 3.1

+4
1
  • MyImage, .
  • onBeforeWrite() MyImage.
  • $image = Image::create(). , , , ParentID .. .
  • $image->SetWidth(...)
  • Product::$has_one, MyImage => MyImage
+2

Source: https://habr.com/ru/post/1606438/


All Articles