Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Members, DataObjectDecorate and ManyManyComplexTableField question

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

Page: 1
Go to End
Author Topic: 1789 Views
  • PeterB
    Avatar
    Community Member
    18 Posts

    Members, DataObjectDecorate and ManyManyComplexTableField question Link to this post

    My that was a mouthful of a title

    I'm building a website for a company and the user who log in are Reps. Not seeing the need to reinvent the window I'm extending the Member object using the code below.

    Reps have a many-to-many relationship with branches. The relationship works, and if I edit a branch I can select as many reps as I need. But... I cannot get a 'Branches' tab to show up when editing a Rep (by going to 'Security' then choosing the 'Reps' group, then editing a user account)!

    I'm certain this is possible and I must be doing something wrong. The error is:

    ERROR [Warning]: Can't figure out the data class of Member
    IN GET /admin/security/EditForm/field/Members/item/2/edit?ajax=1
    Line 32 in /var/www/navs/htdocs/sapphire/forms/HasManyComplexTableField.php

    and I'm not sure what a data class is - a page? A controller?

    <?php
    // Based off the forum module & wiki documentation
    class RepsRole extends DataObjectDecorator {

    function extraStatics() {
    /***/
    return $fields;
    }

    function updateCMSFields(FieldSet &$fields) {
    $fields->addFieldToTab('Root.Main',new TextField("BeneficiaryNumber", "Beneficiary Number"), "Email");
    $fields->addFieldToTab('Root.Main',new TextField("Website", "Website URL"), "Email");

    $modulesTablefield = new ManyManyComplexTableField(
    'Member',
    'RepsBranches',
    'BranchPage',
    array(
    'FirstName' => 'FirstName'
    ),
    'getCMSFields_forPopup'
    );
    $modulesTablefield->setAddTitle( 'A Rep' );

    $fields->addFieldToTab( 'Root.Branches', $modulesTablefield );
    }
    }
    ?>

    Any help would be much appreciated.

  • PeterB
    Avatar
    Community Member
    18 Posts

    Re: Members, DataObjectDecorate and ManyManyComplexTableField question Link to this post

    I got a bit further:

    If I changed 'Member' for $this->owner in the new ManyManyComplexTableField( definition, the error becomes:

    ERROR [User Error]: Couldn't run query:
    SELECT `SiteTree`.*, `SiteTree`.ID, if(`SiteTree`.ClassName,`SiteTree`.ClassName,'SiteTree') AS RecordClassName, `FirstName`, IF(`MemberID` IS NULL, '0', '1') AS Checked
    FROM `SiteTree`
    LEFT JOIN `BranchPage_RepsBranches` ON (`SiteTree`.`ID` = `BranchPageID` AND `MemberID` = '2')
    WHERE (`SiteTree`.ClassName IN ('BranchPage'))
    GROUP BY `SiteTree`.ID
    ORDER BY Sort
    LIMIT 0,10

    Table 'navs.BranchPage_RepsBranches' doesn't exist
    IN GET /admin/security/EditForm/field/Members/item/2/edit?ajax=1
    Line 401 in /var/www/navs/htdocs/sapphire/core/model/MySQLDatabase.php

    Which is not surprising as the table is named BranchPage_Reps.

    Changing my definition to:

    $modulesTablefield = new ManyManyComplexTableField(
    $this->owner,
    'Reps',
    'MinistryPage',
    array(
    'FirstName' => 'FirstName'
    ),
    'getCMSFields_forPopup'
    );

    Results in the error becoming

    Fatal error: Cannot instantiate abstract class Object in /var/www/navs/htdocs/sapphire/core/Object.php on line 115

    Somewhere I'm going wrong big-time in my naming, but I'm not sure where?

  • electronic-womble
    Avatar
    Community Member
    7 Posts

    Re: Members, DataObjectDecorate and ManyManyComplexTableField question Link to this post

    Yep, I've got this exact same problem - anyone got an answer?

  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Re: Members, DataObjectDecorate and ManyManyComplexTableField question Link to this post

    Did anyone find an answer to this? I'm having this same situation and can't fix it.

    Thanks

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