3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1624 Views |
-
Is there any example code of ModelAdmin and $belongs_many_many

6 March 2009 at 8:02pm
Hi,
Just wondering if there is any example code of working with ModelAdmin and $belongs_many_many relationships.
Cheers
Robin
-
Re: Is there any example code of ModelAdmin and $belongs_many_many

13 March 2009 at 9:34pm
I just started playing around with SilverStripe myself.
But this page from the manual was usefull to me.
Hope it helps. -
Re: Is there any example code of ModelAdmin and $belongs_many_many

16 March 2009 at 9:03pm
Hi
Thank you reply. I think the problems I was having where more with ModelAdmin . What I found I had to do is remove the automatically generated tab's and rebuild the forms.
ModelAdmin is amazing for prototyping. What I'm finding is most of the forms that are automatically generated need to reworked in the long run so my hack is working OK for me on multiple levels.
Cheers
Robin
-
Re: Is there any example code of ModelAdmin and $belongs_many_many

17 March 2009 at 6:56pm
@robinp
any chance of sharing some examples? -
Re: Is there any example code of ModelAdmin and $belongs_many_many

17 March 2009 at 9:04pm
Hi guys..
I got this working on v2.3. It's an example of products which could have many categories:
// ---->
class Category extends DataObject {
static $belongs_many_many = array(
'Products' => 'Product'
// ...);
// ---->
class Product extends DataObject {
static $many_many = array(
'Categories' => 'Category'
);function getCMSFields() {
$fields = parent::getCMSFields();
// add categories tab..
$categoryTablefield = new ManyManyComplexTableField(
$this,
'Categories',
'Category',
array( 'Name' => 'Name' )
);
$categoryTablefield->setAddTitle( 'A Category' );
$fields->addFieldToTab( 'Root.Categories', $categoryTablefield );
return $fields;
}// ...
}
// ---->
class MyCRM extends ModelAdmin {
protected static $managed_models = array(
'Category',
'Product',
);static $url_segment = 'crm';
static $menu_title = 'My CRM';
}// ---->
Hope that helps..
-
Re: Is there any example code of ModelAdmin and $belongs_many_many

18 March 2009 at 6:31pm
Hi Geyer,
Thanks for post the code that is basically what I've found myself doing. .
The only thing I'm doing differently is removing the tab that SilverStrip makes after the first save. With line like
$fields->removeByName('Categories');
So the start of my getCMSFields() is like this
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Categories');
// add categories tab..
.....}
Cheers
Robin
| 1624 Views | ||
|
Page:
1
|
Go to Top |



