Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Showing thumnails in dataobject list in CMS?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1740 Views
  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Showing thumnails in dataobject list in CMS? Link to this post

    Hi,
    Following the Product and Storepage DataObjectManger code examples (http://www.carlinowebdesign.com/assets/dataobjectmanager_examples.zip), how can I show thumbnail images of the products in the first column of the data object list in the CMS?
    I would like to be able to immediately see the products image as well as text without clicking anything.

    Thanks,
    Sam

  • UncleCheese
    Avatar
    4085 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Setup a getter and use it in your headers array.

    array(
    'DOMThumbnail' => 'Thumbnail',
    'Title' => 'Title',
    // etc...
    )

    and in your DataObject class:

    public function getDOMThumbnail()
    {
    return $this->YourImage()->CroppedResize(50,50);
    }

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Thanks for quick reply.

    I am getting the error "The website server has not been able to respond to your request" when I try to flush and access the admin page.

    Can you take a look at the code below?

    This is my StorePage.php:
    <?php
    class StorePage extends Page
    {
    static $has_many = array (
    'Products' => 'Product'
    );

    public function getCMSFields()
       {
          $fields = parent::getCMSFields();
          $manager = new DataObjectManager(
    $this,
    'Products',
    'Product',
    array(
    'DOMThumbnail' => 'Thumbnail',
    'Title' => 'Title',
    'Description' => 'Description',
    'Price' => 'Price',
    'OutOfStock' => 'Out Of Stock'
    ),
    'getCMSFields'
    );
                
          $fields->addFieldToTab("Root.Content.Products", $manager);

          return $fields;
       }
    }

    class StorePage_Controller extends Page_Controller
    {
    }

    ?>

    This is my Product.php:

    <?php
    class Product extends DataObject
    {
    static $db = array (
    'Title' => 'Varchar(50)',
    'Description' => 'Text',
    'Price' => 'Decimal',
    'OutOfStock' => 'Boolean'

    );
    static $has_one = array (
    'StorePage' => 'StorePage',
    'ProductImage' => 'Image'
    );

    public function getDOMThumbnail()
    {
    return $this->ProductImage()->CroppedResize(50,50);
    }

    function getCMSFields()
    {
    return new FieldSet(

    new TextField('Title'),
    new TextareaField('Description'),
    new NumericField('Price'),
    new CheckboxField('OutOfStock','This product is out of stock')
    new ImageField('ProductImage'),
    );
    }
    }

    ?>

    Thanks,
    Sam

    PS: I made an error in my last post. I am actually following the Products and StorePage example at http://www.silverstripe.org/dataobjectmanager-module-forum/show/268739?showPost=268739 not your archived zipped examples.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Get your site in dev mode so you can get a usable error.

    Director::set_environment_type('dev');

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Here it is.

    [User Error] Uncaught Exception: Object->__call(): the method 'croppedresize' does not exist on 'Image'
    GET /admin?flush=1

    Line 551 in /home3/islandro/public_html/holybasil/sapphire/core/Object.php
    Source

    542             case isset($config['function']) :
    543                return $config['function']($this, $arguments);
    544             
    545             default :
    546                throw new Exception (
    547                   "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
    548                );
    549          }
    550       } else {
    551          throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'");
    552       }
    553    }
    554    
    555    // -----------------------------------------------------------------------------------------------------------------
    556    
    557    /**

    I am also curious to know how to define the headings array with the intelligent constructor (e.g., new DataObjectManager($this));) in the StorePage.php getCMSFields function.

    Thanks,
    Sam

  • UncleCheese
    Avatar
    4085 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Sorry.. that should be CroppedImage(50,50);

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    Great, it all works now!

    Is it possible to define the headings array with the intelligent constructor or do I need to use the full constructor?

    Thanks,
    Sam

  • UncleCheese
    Avatar
    4085 Posts

    Re: Showing thumnails in dataobject list in CMS? Link to this post

    The only way you could use the intelligent constructor for that is if you defined the headings array in your DataObject class.

    static $summary_fields = array (
    'Title' => 'Title',
    'DOMThumbnail' => 'Thumbail',
    // etc...
    );

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