Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » how to get values ?

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: 1328 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    how to get values ? Link to this post

    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 ?

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: how to get values ? Link to this post

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

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