Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » how to display the name value of and ID in a fieldset

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: 335 Views
  • k_k
    Avatar
    Community Member
    2 Posts

    how to display the name value of and ID in a fieldset Link to this post

    when i choose an item from a dropdown it saves and id, but in other page i have to show the literal value of that id ( id=1 name="jhon") i have to show "jhon" in another cms page, how can i do that?

    now i have to show the name of the category, not the id, and all i have is the ID, how to get the name of the category based in the id of the category i get from the dropdown

    items.php:

    <?php

    class item extends DataObject{
       
       static $db = array(
          'itemName' => 'Varchar(50)',       
          "itemDesc" => "Varchar(100)",
          "price" => "int",
          "catName"=>'Varchar(100)'      
       );
       
       static $has_one = array(
          'cat' => 'cat',
          'page' => 'items'
       );
       
          
       public function getCMSFields_forPopup(){
          $cat= DataObject::get('cat');
          $listCat = $cat ? $listCat = $cat->toDropdownMap('ID','catName') : array();
          
          return new Fieldset(
             new TextField('itemName', 'item Name',10,60),
             new TextField('ItemDesc', 'item Desc',10,150),
             new TextField('price', 'price',10,10),
             new DropdownField('catID', 'Select your category', $listCat )
             
          );
       }
    }
    ?>

    items.php:

    <?php

    class items extends Page {
       static $db = array(
          
       );
       static $has_one = array(
       );
       static $has_many = array(
          'items' => 'item'
       );
       
       public function getCMSFields(){
             
          $cat= DataObject::get('category');
          $catList = $cat? $catList = $cat->toArray('ID','CatName') : array();
          
          
          $f = parent::getCMSFields();
          $f->addFieldToTab("Root.Content.Main", new DataObjectManager(
             $this,
             'items',
             'item',
             array(
                'itemName' => 'item Name',
                'price' => 'price',

    /* now i have to show the name of the category, not the id, and all i have is the ID, how to get the name of the category based in the id of the category i get from the dropdown
    */

                ),
             'getCMSFields_forPopup'
             ));
          $f->removeFieldFromTab("Root.Content.Main", "Content");
          return $f;
       }
       
    }

    class items_Controller extends Page_Controller {
       
       
    }
    ?>

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