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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Go to End


760 Views

Avatar
k_k

Community Member, 2 Posts

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 {
	
	
}
?>