Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » how to get page title and other values on base of Page_ID?

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

    how to get page title and other values on base of Page_ID? Link to this post

    hi

    i use dataobject manager to add different page

    class Objects extends DataObject
    {
       static $db = array (
          'Object_Page_ID' => 'Varchar'
       );
       
       static $has_one = array (
          'TrasyPage' => 'TrasyPage'
       );
             
       public function getCMSFields_forPopup() {
           
          return new FieldSet(
             new SimpleTreeDropdownField('Object_Page_ID','Select Object:')
          );            
       }

    }

    now how to get title, content, other values of Object_Page when i only have Object_Page_ID ?

  • UncleCheese
    Avatar
    4085 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    You've set this up wrong. You should read tutorial #5 on DataObject Relationship Management.

    No need to create foreign keys. Just create the relation and SS will handle it.

    static $db = array (
    );

    static $has_one = array (
    'TrasyPage' => 'TrasyPage',
    'ObjectPage' => 'SiteTree'
    );

    public function getCMSFields_forPopup() {

    return new FieldSet(
    new SimpleTreeDropdownField('ObjectPageID','Select Object:')
    );
    }

    Then you can use $ObjectPage.Title, $ObjectPage.Content, etc..

    or

    <% control ObjectPage %>$Title $Content <% end_control %>

    Also, you should adhere to the convention of using singular names for your classes. Object instead of Objects.

    "Object" of course is already in use, but maybe think of something a little more descriptive than "Object??"

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    hmm it doesnt work or i'm doing something wrong

    so

    this is my Obiekty.php DataObjectManager

    class Obiekty extends DataObject {
       static $db = array (
       );
       
       static $has_one = array (
          'TrasyPage' => 'TrasyPage',
          'ObiektyPage' => 'SiteTree'
       );
             
       public function getCMSFields_forPopup() {
           
          return new FieldSet(
             new SimpleTreeDropdownField('ObiektyPageID','Wybierz obiekt:')
          );            
       }
    }

    TrasyPage.php

    <?php
    class TrasyPage extends Strona {
       static $db = array(
          'Lat' => 'Text',
          'Lng' => 'Text',
          'Rodzaj' => 'Varchar(50)',
          'Trudnosc' => 'Enum("0,1,2,3,4,5","0")',
          'Dlugosc' => 'Varchar(5)',
          'Czas' => 'Float'
       );
       
       static $has_one = array(
       );

       static $has_many = array (
          'NowyObiekt' => 'Obiekty'      
       );

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

          $obiekty = new DataObjectManager(
             $this,
             'NowyObiekt',
             'Obiekty',
             array(
                (what i have to put here when there is no field in db array in the Obiekty ?)
             ),
             'getCMSFields_forPopup'
          );       

          $fields->addFieldToTab("Root.Content.Obiekty", $obiekty);

    (.....)

          return $fields;
       }   
    }

    class TrasyPage_Controller extends Strona_Controller {

    (.....)      
       
    }

    ?>

    and ObiektyPage.php

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

    function getCMSFields() {

    (.....)
    }
    }

    class ObiektyPage_Controller extends Strona_Controller {
    }

    and in template TrasyPage.ss i put what you said

    $ObiektyPage.Title

    or

    <% control ObiektyPage %>
    $Title
    <% end_control %>

    but i get nothing

  • UncleCheese
    Avatar
    4085 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    That's because TrasyPage.php does not have a relationship named "ObiektyPage". Your $has_one array is empty in that class. You have the relationship defined in "Obiekty"

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    uhh i done it
    thanks UncleCheese

    but now i have the same problem like in Widget
    i'm using DataObjectManager to add Points to GoogleMaps

    so one TrasyPage (in english BicyclePath) can has many ObiektyPange (ObjectPage)
    for example BicyclePath named "Mogiła" has ObjectPages like "Zalew Nowohucki", "Las Mogilski", "Zoo"
    and it looks like here http://wilgocki.net/screen1.jpg

    but when i click on some marker the window always opened on last Object which i added in CMS
    Zoo is last added Object

    Google Maps
    http://wilgocki.net/screen3.jpg

    template code

    <% control Obiekty %>
       var marker = new GMarker(new GLatLng($ObiektyPage.Lat,$ObiektyPage.Lng),{title: "$ObiektyPage.Title"});
       mapa.addOverlay(marker);
             
       GEvent.addListener(marker,"click",function() {
        marker.openInfoWindowHtml('<div class="dymek"><h2>$ObiektyPage.Title</h2><% control Zdjecie %><% control CroppedImage(90,50) %><img title="" src="$URL" width="90" height="50" style="float: left; margin-right: 5px;" /><% end_control %><% end_control %><p>$ObiektyPage.Zajawka</p><p><a href="$ObiektyPage.Link">przeczytaj opis</a></p></div>');
       });      
    <% end_control %>

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    i had to return marker in another function

    <% control Obiekty %>
       var nazwa = '$ObiektyPage.Title';
       var lat = '$ObiektyPage.Lat';
       var lng = '$ObiektyPage.Lng';
             
       addmarker(nazwa,lat,lng);      
    <% end_control %>

    function addmarker(Nazwa,Lat,Lng) {
       var marker = new GMarker(new GLatLng(Lat,Lng));
             
       GEvent.addListener(marker,"click",function() {
       marker.openInfoWindowHtml('<div class="dymek"><h2>'+Nazwa+'</h2><% control Zdjecie %><% control CroppedImage(90,50) %><img title="" src="$URL" width="90" height="50" style="float: left; margin-right: 5px;" /><% end_control %><% end_control %><p>$ObiektyPage.Zajawka</p><p><a href="$ObiektyPage.Link">przeczytaj opis</a></p></div>');
       });
       mapa.addOverlay(marker);
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: how to get page title and other values on base of Page_ID? Link to this post

    You could have done this a bit more cleanly by putting the custom script in your controller, using the requirements class. Glad it's working, though.

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