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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Show variable instead ClassID in BO


Go to End


6 Posts   979 Views

Avatar
Dr0gaz

Community Member, 37 Posts

11 January 2011 at 1:50am

Hi guys i have a class:

class Marca extends DataObject {

static $db = array(
'Nomemar' => 'Varchar(255)'
);

static $has_many = array(
'Modelos' => 'Modelo'
);

static $belongs_many_many = array(
'Produtos' => 'Produto'
);

static $searchable_fields = array(
'Nomemar'
);

static $summary_fields = array(
'Nomemar' => 'Nome'
);

function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->push(new TextField('Nomemar','Nome Marca')
);

return $fields;
}

function forTemplate() { return $this->Nomemar; }
}

and:

class Modelo extends DataObject {

static $db = array(
'Nomemod' => 'Varchar(255)'
);

static $has_one = array(
'Marcas' => 'Marca'
);

/*
static $belongs_many_many = array(
'Produtos' =>'Produto'
);*/

static $summary_fields = array(
'Nomemod' => 'Nome Modelo',
'Nomemar'=>'NomeMARCAS'
);

function getCMSFields()
{
$fields = parent::getCMSFields();

$fields ->push(new TextField('Nomemod','Nome Modelo'));

$modulesMarcas = new HasOneDataObjectManager(
$this,
'Marcas',
'Marca',
array(
'Nomemar' => 'Nome'
),
'getCMSFields'
);

$fields->removeFieldFromTab('Root', 'Main'); // replace the tab with MMDOM tab
$fields->push( $modulesMarcas );

return $fields;

}

function forTemplate() { return $this->Nomemod; }
}

and another class Product

where i have

$managermod = new ManyManyDataObjectManager(
$this, // Controller
'Modelos', // Source name
'Modelo', // Source class
array('Nomemod' => 'Nome Modelo',
'MarcasID' => 'Nome Marcas'
),
'getCMSFields' );

$f->removeFieldFromTab('Root', 'Modelos'); // replace the tab with MMDOM tab
$f->addFieldToTab('Root.Modelos', $managermod);

so i want have 'MarcasNomemar' => 'Nome Marcas' instead 'MarcasID' => 'Nome Marcas' in my backoffice

sugestions...

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 January 2011 at 4:03am

Just use a custom getter..

public function getMarcasNomemar() {
if($m = $this->Marcas()) {
return $m->Nomemar;
}
return false;
}

array (
'MarcasNomemar' => 'Nome Marcas'
);

Avatar
Dr0gaz

Community Member, 37 Posts

11 January 2011 at 5:04am

dont worked...

so... this code:

public function getMarcasNomemar() {
if($m = $this->Marcas()) {
return $m->Nomemar;
}
return false;
}

i have put in... class Marca?

and, this

array (
'MarcasNomemar' => 'Nome Marcas'
);

go to "ManyManyDataObjectManager" right?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 January 2011 at 6:34am

No, that function belongs in Modelo.. the class being managed by the DOM..

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

Avatar
Dr0gaz

Community Member, 37 Posts

11 January 2011 at 6:54am

oh yeah...

Awesome... thank's UncleCheese! Already worked....

Avatar
Dr0gaz

Community Member, 37 Posts

12 January 2011 at 4:43am

Edited: 12/01/2011 4:43am

i' have the same for class Produto how i do one see that the relations are difrent ...

Are the same way?