Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Show variable instead ClassID in BO

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 671 Views
  • Dr0gaz
    Avatar
    Community Member
    37 Posts

    Show variable instead ClassID in BO Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show variable instead ClassID in BO Link to this post

    Just use a custom getter..

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

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

  • Dr0gaz
    Avatar
    Community Member
    37 Posts

    Re: Show variable instead ClassID in BO Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show variable instead ClassID in BO Link to this post

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

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

  • Dr0gaz
    Avatar
    Community Member
    37 Posts

    Re: Show variable instead ClassID in BO Link to this post

    oh yeah...

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

  • Dr0gaz
    Avatar
    Community Member
    37 Posts

    Re: Show variable instead ClassID in BO Link to this post

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

    Are the same way?

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