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.

Customising the CMS /

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

Members, DataObjectDecorate and ManyManyComplexTableField question


Go to End


4 Posts   2489 Views

Avatar
PeterB

Community Member, 18 Posts

8 August 2009 at 3:10am

Edited: 08/08/2009 3:11am

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.

Avatar
PeterB

Community Member, 18 Posts

8 August 2009 at 3:22am

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?

Avatar
electronic-womble

Community Member, 7 Posts

22 November 2011 at 12:34am

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

Avatar
Lazarus404

Community Member, 72 Posts

5 April 2012 at 11:12am

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

Thanks