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 page title and other values on base of Page_ID?


Reply


7 Posts   2795 Views

Avatar
snaip

Community Member, 180 Posts

6 September 2009 at 1:38am

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 ?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

6 September 2009 at 3:05am

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??"

Avatar
snaip

Community Member, 180 Posts

6 September 2009 at 7:21am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

6 September 2009 at 8:10am

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"

Avatar
snaip

Community Member, 180 Posts

6 September 2009 at 10:44pm

Edited: 06/09/2009 11:05pm

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 [url]http://wilgocki.net/screen1.jpg[/url]

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
[url]http://wilgocki.net/screen3.jpg[/url]

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 %>

Avatar
snaip

Community Member, 180 Posts

7 September 2009 at 7:02am

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);
}

:)

Avatar
UncleCheese

Forum Moderator, 4096 Posts

7 September 2009 at 9:28am

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.