Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Problem with SiteTree in DOM

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: 1936 Views
  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Problem with SiteTree in DOM Link to this post

    Can anyone see if maybe I am missing something. My luck a comma!

    I get the following error when trying to include a site treet drop down in my File DOM.

    [User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'SiteTree'
    GET /admin
    Line 724 in /home/content/28/4118128/html/sapphire/core/Object.php

    THANKS!

    GOLDSPONSOR.PHP

    <?php

    class GoldSponsor extends DataObject
    {
       static $db = array (
          'CompanyName' => 'Text',
          'CompanyWebAddress' => 'Text'
       );

       static $has_one = array (
          'Attachment' => 'File',
          'GoldSponsorPage' => 'GoldSponsorPage'
          'GoldRelatedArticle' => 'SiteTree',
       
             
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('CompanyName'),
             new TextField('CompanyWebAddress'),
             new SimpleTreeDropdownField('GoldRelatedArticleID', "Related Page", 'SiteTree'),
             new FileIFrameField('Attachment')
          );
       }
    }

    ?>

    GOLDSPONSORPAGE.PHP

    <?php

    class GoldSponsorPage extends RightNav
    {
       static $has_many = array (
          'GoldSponsors' => 'GoldSponsor'
       );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'GoldSponsors', // Source name
             'GoldSponsor', // Source class
             'Attachment', // File name on DataObject
             array(
                'CompanyName' => 'CompanyName',
                'CompanyWebAddress' => 'CompanyWebAddress',
                'GoldRelatedArticle' => 'GoldRelatedArticle'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
    $f->addFieldToTab("Root.Content.GoldSponsor",$manager);
    return $f;
       }
    }

    class GoldSponsorPage_Controller extends RightNav_Controller {

    }

    ?>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Problem with SiteTree in DOM Link to this post

    This happens in the CMS? That looks like the type of error you'd get on the frontend.

    Is there anymore of that trace?

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

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: Problem with SiteTree in DOM Link to this post

    It happens when I try to load the front end page, or after I create an item in the cms i get the "page says" gray box and it dumps the following message. It keeps mentioning the blog entry too, which is weird.

    The page at XXXXXX.com says:ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'BlogEntry'
    IN POST /admin/getitem?ID=176&ajax=1
    Line 724 in /home/content/28/4118128/html/sapphire/core/Object.php

    Source
    ======
    715:             
    716:             default :
    717:                throw new Exception (
    718:                   "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config,
    true)
    719:                );
    720:          }
    721:       } else {
    722:          // Please do not change the exception code number below.
    723:          
    * 724:          throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'",
    2175);
    725:       }
    726:    }
    727:    
    728:    //
    -----------------------------------------------------------------------------------------------------------------
    729:    
    730:    /**

    Trace
    =====
    <ul>Object->__call(forTemplate,Array)
    line 447 of ViewableData.php

    BlogEntry->forTemplate()
    line 447 of ViewableData.php

    ViewableData->XML_val(PlatinumRelatedArticle)
    line 1341 of TableListField.php

    TableListField_Item->Fields()
    line 603 of DataObjectManager.php

    DataObjectManager_Item->Fields()
    line 369 of ViewableData.php

    ViewableData->obj(Fields)
    line 590 of .cache.home.content.28.4118128.html.dataobject_manager.templates.FileDataObjectManager.ss

    include(/home/content/28/4118128/html/silverstripe-cache/.cache.home.content.28.4118128.html.dataobject_manager.templates.FileDataObjectManager.ss)
    line 420 of SSViewer.php

    SSViewer->process(FileDataObjectManager)
    line 342 of ViewableData.php

    ViewableData->renderWith(FileDataObjectManager)
    line 275 of ComplexTableField.php

    ComplexTableField->FieldHolder()
    line 266 of DataObjectManager.php

    DataObjectManager->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 73 of .cache.home.content.28.4118128.html.sapphire.templates.TabSetFieldHolder.ss

    include(/home/content/28/4118128/html/silverstripe-cache/.cache.home.content.28.4118128.html.sapphire.templates.TabSetFieldHolder.ss)
    line 420 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 58 of .cache.home.content.28.4118128.html.sapphire.templates.TabSetFieldHolder.ss

    include(/home/content/28/4118128/html/silverstripe-cache/.cache.home.content.28.4118128.html.sapphire.templates.TabSetFieldHolder.ss)
    line 420 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 77 of .cache.home.content.28.4118128.html.sapphire.templates.Includes.Form.ss

    include(/home/content/28/4118128/html/silverstripe-cache/.cache.home.content.28.4118128.html.sapphire.templates.Includes.Form.ss)
    line 420 of SSViewer.php

    SSViewer->process(Form)
    line 342 of ViewableData.php

    ViewableData->renderWith(Array)
    line 1085 of Form.php

    Form->forTemplate()
    line 1112 of Form.php

    Form->formHtmlContent()
    line 384 of LeftAndMain.php

    LeftAndMain->getitem(SS_HTTPRequest)
    line 193 of Controller.php

    Controller->handleAction(SS_HTTPRequest)
    line 137 of RequestHandler.php

    RequestHandler->handleRequest(SS_HTTPRequest)
    line 147 of Controller.php

    Controller->handleRequest(SS_HTTPRequest)
    line 281 of Director.php

    Director::handleRequest(SS_HTTPRequest,Session)
    line 124 of Director.php

    Director::direct(/admin/getitem)
    line 127 of main.php

    </ul>

    [/code/

  • UncleCheese
    Avatar
    4085 Posts

    Re: Problem with SiteTree in DOM Link to this post

    You're probably trying to render a SiteTree object on the template?? Like this, maybe?

    $GoldRelatedArticle

    You can't do that, of course, because there's nothing to render. $GoldRelatedArticle.Title will give you something, but not the object itself.

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

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: Problem with SiteTree in DOM Link to this post

    The weird thing is, I haven't even created a layout page yet for it. Havn't even got that far! Is the code i am using look fine? Maybe need to just start from scratch again!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Problem with SiteTree in DOM Link to this post

    It's in your headings array:

    'GoldRelatedArticle' => 'GoldRelatedArticle'

    You can't render $GoldRelatedArticle as a column in the table. You need to choose what field you want to show. Try this:

    public function getGoldTitle() {
    if($page = $this->GoldRelatedArticle()) {
    return $page->Title;
    }
    return false;
    }

    and change your headings array to use:

    'GoldTitle' => 'Related article title'

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

  • qbahamutp
    Avatar
    Community Member
    8 Posts

    Re: Problem with SiteTree in DOM Link to this post

    Apologies for the bump. I'm just curious about how you can make this work. I've got a similar issue going on, but it's a low-priority, really.

    I'm just curious about the principle of controlling the content of DOM columns using functions.

    Regarding the example that UC wrote in the above post: how does it know to refer to the getGoldTitle()function based on its array key ('GoldTitle')?
    I've tried adding a function to the page's controller that always returns "foo", but I can't even get that to work.

    I'm hoping someone can help me figure this one out. Thanks in advance.

  • abschwoerung
    Avatar
    Community Member
    3 Posts

    Re: Problem with SiteTree in DOM Link to this post

    Well, you basically tell the DOM in the 4th parameter with an array which method in the DataObject to use to display in the overview.
    For example:

    new DataObjectManager(
    $this,
    'TeaserImages',
    'TeaserImage',
    array(
    'Image' => 'Bild',
    'getSelectedSiteTitle' => 'verlinkte Seite',
    ),
    'getCMSFields_forPopup'
    )

    will call TeaserImage->getSelectedSiteTitle() for displaying a value in the second column of the DOM overview. Within the DataObject inherited class put the method and access the DataObjects values (example is for a SiteTree):

    public function getSelectedSiteTitle() {
    return $this->obj('LinkTo')->Title;
    }

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