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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

how to get values ?


Reply

2 Posts   1336 Views

Avatar
snaip

31 July 2009 at 10:19am Community Member, 180 Posts

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

1 August 2009 at 1:21am (Last edited: 1 August 2009 1:22am), Community Member, 180 Posts

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()"