3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 777 Views |
-
Member object and Data objects

20 October 2010 at 1:49am
Hi Guys,
I've set up a site and I'm currently plumbing in some custom functionality - one of the things I need to do is add some fields and data to the member object. As such I've:
- Extended the Member using a DataObjectDecorator
- Created two data objects, both of which hold trivial data (lets call them Foo and Bar)
- Created a many to many relationship between Member and my two data objects - I.e. all of my members can be associated with any or all of the data objects
- Used 2 ManyManyComplexTableField in updateCMSFields on the aforementioned DataObjectDecorator to display/edit the relationships in the Member pop up view.
Now, my problems are that when I view a member, I can't add a new Foo or Bar as there is no "Add new Foo" button. I've gotten around this by instead of going through the pop up in security (when you click on a user), going straight to the following page in my browser:
/admin/security/EditForm/field/Members/item/2/edit
This has allowed me to create Foo's and Bar's as much as I want, and they now show up on both the direct (above URL) and regular (view Security) Member views. However I can't associated my Member (heh) with any of the Foo or Bar's I have created - I check the boxes, save, it's saves without errors but no associations are created. I've double checked in the database.
So my question is basically: Is associating data objects with Members even possible, or have I missed the big entry in the wiki that states "Members can't be associated with Data objects you fool".
Cheers
Robbie
- Extended the Member using a DataObjectDecorator
-
Re: Member object and Data objects

20 October 2010 at 2:19am
Firstly I have not tried many_many for extending the members so this is just thoughts
I'd use the great http://www.silverstripe.org/multiselectfield-module/ to be able to "re-use" and set up this many_many relationship.
Also I extend the member using...
_config.php
Object::add_extension('Member', 'CustomMember');
CustomMember.php
class CustomMember extends DataObjectDecorator {
function extraStatics()
{
return array(
'has_many' => array(
'Foo' => 'Foo',
),
);
}
}Hope this helps!
-
Re: Member object and Data objects

20 October 2010 at 5:03am
Hi Swaiba,
Thanks for your help. I've actually already done that part of work - it's after that point that I have the issues with creating new "Foo" objects, and then associating them with Members.
Cheers
Robbie
-
Re: Member object and Data objects

20 October 2010 at 5:20am Last edited: 20 October 2010 5:22am
Oh, well I would normally use ModelAdmin for all CRUD operations so for the Foo and Bar info to be selectable in the MultiSelect you could use code like...
for each data object...
class Foo extends DataObject
{
static $db = array('fielda'=>'Text');
}to CRUD the records in the Many Many thing...
class FooBarAdmin extends ModelAdmin
{
static $managed_models = array(
'Foo',
'Bar',
);static $url_segment = 'foobaradmin';
static $menu_title = 'Foo Bar Admin';
}Is that what you are after?
-
Re: Member object and Data objects

20 October 2010 at 9:17pm
Hi Swaiba,
Cheers for that, it's given me a good idea for a plan B!
Basically my issue is adding data objects against a Member - I.e. is it possible? I'm increasingly thinking it isn't. The system picks up on them, but the CRUD operations seem broken.
Cheers
Robbie
-
Re: Member object and Data objects

20 October 2010 at 10:14pm
Well it is a double edged sword - assuming there are no complications with CTF and having popups - as I think about it...
with the multi select and have a nice chooser, but this only selects existing objects
with the main sapphire scaffolding you get the tabs and the add button, but this then wont let you share Foo and Bar objects created there with others...oh and have you tried putting 'Member' into your managed models in a Model Admin? this would mean the first has_many would be on a tab, not in a tab of a popup
-
Re: Member object and Data objects

20 October 2010 at 10:18pm
I'll give that approach a try, failing that, there is a plan b I can tackle it with.
Cheers for all your help
Robbie
| 777 Views | ||
|
Page:
1
|
Go to Top |


