Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Thumbnail DataObjectManager Image

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1971 Views
  • web2works
    Avatar
    Community Member
    50 Posts

    Thumbnail DataObjectManager Image Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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 {

    }

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

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

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Thumbnail DataObjectManager Image Link to this post

    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

    1971 Views
Page: 1 2
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.