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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Showing thumnails in dataobject list in CMS?


Reply

8 Posts   1830 Views

Avatar
Samba Sam

6 December 2009 at 4:48am Community Member, 85 Posts

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

Avatar
UncleCheese

6 December 2009 at 5:16am 4085 Posts

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);
}

Avatar
Samba Sam

6 December 2009 at 9:01am (Last edited: 6 December 2009 9:07am), Community Member, 85 Posts

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.

Avatar
UncleCheese

6 December 2009 at 9:52am 4085 Posts

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

Director::set_environment_type('dev');

Avatar
Samba Sam

6 December 2009 at 5:57pm (Last edited: 6 December 2009 6:07pm), Community Member, 85 Posts

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

Avatar
UncleCheese

6 December 2009 at 6:02pm 4085 Posts

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

Avatar
Samba Sam

6 December 2009 at 6:13pm (Last edited: 6 December 2009 6:15pm), Community Member, 85 Posts

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

Avatar
UncleCheese

7 December 2009 at 4:06am 4085 Posts

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...
);