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

how to get values ?


Go to End


2 Posts   1989 Views

Avatar
snaip

Community Member, 181 Posts

31 July 2009 at 10:19am

hi

i want to get values but i dont know how

my ObjectPage,php

<?php
class ObiektyPage extends Strona {
   	static $db = array(
   		'Zajawka' => 'Text',
   		'Lat' => 'Varchar(50)',
   		'Lng' => 'Varchar(50)'
   	);
   	
   	static $has_one = array(
   		'Zdjecie' => 'Image'
   	);

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

		$fields->addFieldToTab("Root.Content.Main", new TextareaField("Zajawka", "Zajawka:",4),"Content");
		
		$fields->addFieldToTab("Root.Content.Zdjęcie główne", new ImageField("Zdjecie"));
		
		$fields->addFieldToTab("Root.Content.Wspolrzedne", new TextField("Lat", "Lat:"));
		$fields->addFieldToTab("Root.Content.Wspolrzedne", new TextField("Lng", "Lng:"));
		
		return $fields;
	}
   	   
}



class ObiektyPage_Controller extends Strona_Controller {
 
}
 
?>

my DataObjectManager

<?php 
class Obiekty extends DataObject
{
	static $db = array (
		'Nazwa' => 'Text',
		'Obiekt' => 'Text',
   		'Lat' => 'Varchar(50)',
   		'Lng' => 'Varchar(50)'
	);
	
	static $has_one = array (
		'TrasyPage' => 'TrasyPage'
	);
			
	public function getCMSFields_forPopup() {
	  
   		$stuff = DataObject::get("ObiektyPage");
      		$map = $stuff? $stuff->toDropdownMap():array();
	  	
		return new FieldSet(
			new TextField('Nazwa'),
			new DropdownField('Obiekt','Obiekt',$map)	
		);
	}
}
?>

and my TrasyPage.php

<?php
class TrasyPage extends Strona {
   	static $db = array(
   	);
   	
   	static $has_one = array(
   	);
   
	static $has_many = array (
		'Trasy' => 'Trasy',
		'Obiekty' => 'Obiekty'
	);   

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

		$manager = new DataObjectManager(
			$this, // Controller
			'Trasy', // Source name
			'Trasy', // Source class
			array('Nr' => 'Nr', 'Lat' => 'Lat', 'Lng' => 'Lng'), // Headings
			'getCMSFields_forPopup' // Detail fields function or FieldSet	
		);

		$obiekty = new DataObjectManager(
			$this, // Controller
			'Obiekty', // Source name
			'Obiekty', // Source class
			array('Nazwa' => 'Nazwa', 'Obiekt' => 'Obiekt'), // Headings
			'getCMSFields_forPopup' // Detail fields function or FieldSet	
		);

		$fields->addFieldToTab("Root.Content.Wspolrzedne", $manager);
		$fields->addFieldToTab("Root.Content.Obiekty", $obiekty);
		return $fields;
	}	   
}



class TrasyPage_Controller extends Strona_Controller {
 
}
 
?>

1) i add object into ObiektPage (Name, some Text, Coordinates: Lat / Lng, Image)
2) in TrasyPage i add objects by DropdownField (Data Object Manager) but I want to get the coordinates Lat / Lng of chosen object and put into Lat/Lng fields.. i don't know how

any idea ?

Avatar
snaip

Community Member, 181 Posts

1 August 2009 at 1:21am

Edited: 01/08/2009 1:22am

i tried with

	function onAfterWrite() {
   		$cp = DataObject::get_by_id('ObiektyPage',$this->ID); 
   		$cp->Lat = $this->Lat;
   		$cp->Lng = $this->Lng;
   		$cp->write();
		return parent::onAfterWrite(); 
 	}

in class Obiekty extends DataObject but have an error "Call to undefined method stdClass::write()"