7913 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1582 Views |
-
Showing thumnails in dataobject list in CMS?

6 December 2009 at 4:48am
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 -
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 5:16am
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);
} -
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 9:01am Last edited: 6 December 2009 9:07am
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,
SamPS: 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.
-
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 9:52am
Get your site in dev mode so you can get a usable error.
Director::set_environment_type('dev');
-
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 5:57pm Last edited: 6 December 2009 6:07pm
Here it is.
[User Error] Uncaught Exception: Object->__call(): the method 'croppedresize' does not exist on 'Image'
GET /admin?flush=1Line 551 in /home3/islandro/public_html/holybasil/sapphire/core/Object.php
Source542 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 -
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 6:02pm
Sorry.. that should be CroppedImage(50,50);
-
Re: Showing thumnails in dataobject list in CMS?

6 December 2009 at 6:13pm Last edited: 6 December 2009 6:15pm
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 -
Re: Showing thumnails in dataobject list in CMS?

7 December 2009 at 4:06am
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...
);
| 1582 Views | ||
|
Page:
1
|
Go to Top |

