7912 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 241 Views |
-
how to display the name value of and ID in a fieldset

26 February 2012 at 2:08pm
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 {
}
?>
| 241 Views | ||
|
Page:
1
|
Go to Top |

