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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Thumbnail DataObjectManager Image


Go to End


10 Posts   3274 Views

Avatar
web2works

Community Member, 50 Posts

16 September 2010 at 7:22am

Hi, I'm trying to add a dataobject to my homepage to be used as a jquery content slider containing:
- text
- image
- background
- cssID

How would I go about resizing the image in the admin area?

Also I have tried <? control slogan %> and get the follow error below when I access the homepage or visable here: http://www.web2works.co.uk

Thanks for any help.
Ben

------------- homepage.php -------------------
<?php
class Homepage extends Page {

static $singular_name = 'Homepage';
static $plural_name = 'Home';

static $has_many = array(
'Slogan' => 'Slogan'
);

static $icon = "cms/images/treeicons/home";

public function getCMSFields(){
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Slogan", new DataObjectManager(
$this,
'Slogan',
'Slogan',
array(
'SloganText'=> 'Text',
'CSSid' => 'CSS ID',
'SloganImage' => 'Image',
'SloganBackground' => 'Background'
),
'getCMSFields_forPopup'
));
return $f;
}

}

class Homepage_Controller extends Page_Controller {

}

?>

-------------- slogan.php -----------------
<?php
class Slogan extends DataObject {

static $db = array (
'SloganText' => 'Varchar(100)',
'CSSid' => 'Varchar(50)'
);

static $has_one = array (
'Homepage' => 'Homepage',
'SloganImage' => 'Image',
'SloganBackground' => 'Image'
);

static $singular_name = 'Slogan';
static $plural_name = 'Slogans';

public function getCMSFields_forPopup(){
return new FieldSet(
new TextField('SloganText'),
new TextField('CSSid'),
new ImageField('SloganImage'),
new ImageField('SloganBackground')
);
}

}
?>

----------- Error Page --------------
[User Error] Couldn't run query: SELECT "Slogan"."ClassName", "Slogan"."Created", "Slogan"."LastEdited", "Slogan"."SloganText", "Slogan"."CSSid", "Slogan"."SloganImageID", "Slogan"."SloganBackgroundID", "Slogan"."ID", CASE WHEN "Slogan"."ClassName" IS NOT NULL THEN "Slogan"."ClassName" ELSE 'Slogan' END AS "RecordClassName" FROM "Slogan" WHERE ("ParentID" = '1') Unknown column 'Slogan.SloganText' in 'field list'
GET /web2works/

Line 536 in C:\wamp\www\web2works\sapphire\core\model\MySQLDatabase.php
Source

527 }
528
529 function databaseError($msg, $errorLevel = E_USER_ERROR) {
530 // try to extract and format query
531 if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
532 $formatter = new SQLFormatter();
533 $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
534 }
535
536 user_error($msg, $errorLevel);
537 }
538
539 /**
540 * Return a boolean type-formatted string
541 *
542 * @param array $values Contains a tokenised list of info about this data type

Trace

* Couldn't run query: SELECT "Slogan"."ClassName", "Slogan"."Created", "Slogan"."LastEdited", "Slogan"."SloganText", "Slogan"."CSSid", "Slogan"."SloganImageID", "Slogan"."SloganBackgroundID", "Slogan"."ID", CASE WHEN "Slogan"."ClassName" IS NOT NULL THEN "Slogan"."ClassName" ELSE 'Slogan' END AS "RecordClassName" FROM "Slogan" WHERE ("ParentID" = '1') Unknown column 'Slogan.SloganText' in 'field list'
Line 536 of MySQLDatabase.php
* MySQLDatabase->databaseError(Couldn't run query: SELECT "Slogan"."ClassName", "Slogan"."Created", "Slogan"."LastEdited", "Slogan"."SloganText", "Slogan"."CSSid", "Slogan"."SloganImageID", "Slogan"."SloganBackgroundID", "Slogan"."ID", CASE WHEN "Slogan"."ClassName" IS NOT NULL THEN "Slogan"."ClassName" ELSE 'Slogan' END AS "RecordClassName" FROM "Slogan" WHERE ("ParentID" = '1') | Unknown column 'Slogan.SloganText' in 'field list',256)
Line 134 of MySQLDatabase.php
* MySQLDatabase->query(SELECT "Slogan"."ClassName", "Slogan"."Created", "Slogan"."LastEdited", "Slogan"."SloganText", "Slogan"."CSSid", "Slogan"."SloganImageID", "Slogan"."SloganBackgroundID", "Slogan"."ID", CASE WHEN "Slogan"."ClassName" IS NOT NULL THEN "Slogan"."ClassName" ELSE 'Slogan' END AS "RecordClassName" FROM "Slogan" WHERE ("ParentID" = '1'),256)
Line 126 of DB.php
* DB::query(SELECT "Slogan"."ClassName", "Slogan"."Created", "Slogan"."LastEdited", "Slogan"."SloganText", "Slogan"."CSSid", "Slogan"."SloganImageID", "Slogan"."SloganBackgroundID", "Slogan"."ID", CASE WHEN "Slogan"."ClassName" IS NOT NULL THEN "Slogan"."ClassName" ELSE 'Slogan' END AS "RecordClassName" FROM "Slogan" WHERE ("ParentID" = '1'),256)
Line 386 of SQLQuery.php
* SQLQuery->execute()
Line 1262 of DataObject.php
* DataObject->getComponents(Slogan)
* call_user_func_array(Array,Array)
Line 711 of Object.php
* Object->__call(slogan,Array)
* Homepage->slogan()
* call_user_func_array(Array,Array)
Line 693 of Object.php
* Object->__call(Slogan,Array)
* Homepage_Controller->Slogan()
Line 369 of ViewableData.php
* ViewableData->obj(Slogan,,1,,)
Line 826 of ViewableData.php
* ViewableData_Customised->obj(Slogan)
Line 146 of .cacheC..wamp.www.web2works.themes.web2works.templates.Page.ss
* include(C:\WINDOWS\Temp\silverstripe-cacheC--wamp-www-web2works\.cacheC..wamp.www.web2works.themes.web2works.templates.Page.ss)
Line 392 of SSViewer.php
* SSViewer->process(Homepage_Controller)
Line 202 of Controller.php
* Controller->handleAction(SS_HTTPRequest)
Line 134 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
* Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
* ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 111 of RootURLController.php
* RootURLController->handleRequest(SS_HTTPRequest)
Line 283 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 127 of Director.php
* Director::direct(/)
Line 127 of main.php

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 September 2010 at 7:44am

Looks like you have a typo..

<? control slogan %>

should be

<% control Slogan %>

Also, you should probably rename that relationship.

$has_many = array (
'Slogans' => 'Slogan'
);

has_many and many_many relationships should always be in the plural form.

To handle image resizing, just use $YourImage.CroppedImage(100,100) or $YourImage.SetWidth(100), etc..

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
web2works

Community Member, 50 Posts

16 September 2010 at 8:39am

Firstly I now have the table in the admin area and succsefully uploaded the 2 images. Although is there any way to resize the images in the table row? I dont want to edit the CMS template files if possible.

Secondly I have the following in my template file
<% control slogan %>
<li id="{$CSSid}" style="background-image: url('{$SloganBackground.URL}');">
<p>{$SloganImage.SetWidth(100)}
{$SloganText}</p>
</li>
<% end_control %>

I am new to Silverstripe after reading through the book there was not as much referenec to dataobjects as I needed. Is this the right way to achieve the simple jquery feature

Changes to files:

Slogans.php
<?php
class Slogans extends DataObject {
static $db = array (
'SloganText' => 'Varchar(100)',
'CSSid' => 'Varchar(50)'
);

static $has_one = array (
'SloganImage' => 'Image',
'SloganBackground' => 'Image',
'Homepage' => 'Homepage'
);

static $singular_name = 'Slogans';
static $plural_name = 'Slogans';

public function getCMSFields_forPopup() {
return parent::getCMSFields();
}
}

Homepage.php
<?php
class Homepage extends Page {

static $singular_name = 'Homepage';
static $plural_name = 'Home';

static $has_many = array(
'Slogans' => 'Slogan'
);

static $icon = "cms/images/treeicons/home";

public function getCMSFields(){
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Slogan", new DataObjectManager(
$this,
'Slogan',
'Slogans',
array(
'SloganText'=> 'Text',
'CSSid' => 'CSS ID',
'SloganImage' => 'Image',
'SloganBackground' => 'Background'
),
'getCMSFields_forPopup'
));
return $f;
}

}

class Homepage_Controller extends Page_Controller {

}

Avatar
web2works

Community Member, 50 Posts

16 September 2010 at 6:02pm

Edited: 16/09/2010 11:32pm

I managed to sort this thanks. It was a case issue that has cached.

Avatar
Garrett

Community Member, 245 Posts

12 October 2010 at 7:52am

I think this guy was asking how to resize the images in the CMS admin panel. I have ALWAYS wanted to know how to do this. I can't figure out WHERE to do it. I'm well aware of the CroppedImage() and SetWidth/Height() methods, I just don't know where to use them in the CMS code.

Anyone? My images are so large that you can't see any of the other data columns in my DataObject_Manager.

//Garrett

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 October 2010 at 8:05am

Just use a custom getter..

public function getDOMThumbnail() {
if($i = $this->YourImage()) {
return $i->CroppedImage(50,50);
}
return false;
}

and in your headings array:

'DOMThumbnail' => 'Resized Image!!!'

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Garrett

Community Member, 245 Posts

12 October 2010 at 8:11am

Edited: 12/10/2010 8:12am

Thanks UncleCheese (as always), but I need a LITTLE more info-- first, what is $i in that code, and second, I assume by headers array you mean:

static $field_names = array(
     //'Image' => 'Image',
     'DOMThumbnail' => 'Resized Image!!!', 
     'ImageAltText' => 'Image Alt Text',
     'URL' => 'URL',
     'SortOrder' => 'Sort Order',
);

Yes?

//Garrett

Avatar
Garrett

Community Member, 245 Posts

12 October 2010 at 8:19am

Never mind, @UC -- I got it. THANKS! I think I was just a little confused by the fact that you put getDOMThumbnail as the fxn name but DOMThumbnail when you called it ;)

This is going to be a fantastic improvement in my UI. Much appreciated.

//Garrett

Go to Top