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

Need help to show dataobject on page


Go to End


27 Posts   4505 Views

Avatar
Webdoc

Community Member, 349 Posts

12 September 2010 at 4:04am

Edited: 12/09/2010 4:07am

Made some things for real estate website

Nimekiri.php (Page type)

<?php
class Nimekiri extends Page 
{ 
   static $has_many = array ( 
      'Objektid' => 'Objekt' 
   );    
    
   public function getCMSFields() 
   { 
      $f = parent::getCMSFields();
	$f->removeFieldFromTab("Root.Content.Main","Content");
      $manager = new DataObjectManager( 
         $this, 
         'Objektid', 
         'Objekt', 
         array('Objektinimi' => 'Objekti nimi', 'Kirjeldus' => 'Objekti kirjeldus'), 
         'getCMSFields_forPopup' 
      ); 
      $f->addFieldToTab('Root.Content.Main', $manager); 
      return $f; 
   } 

}


class Nimekiri_Controller extends Page_Controller {
 	function ObjektList() {
		return DataObject::get("Objekt");
	}


}
?>

Objekt.php (Dataobject)

<?php
class Objekt extends DataObject 
{ 
	static $db = array ( 
	'Objektinimi' => 'Text', 
	'Kirjeldus' => 'HTMLText',
	'Hind' => 'Text',
	'Elamutyyp' => "Enum('Korter, Maja, Aripind, Suvila, Ridaelamu, Paarismaja, Maatykk')",
	'Soojaveetyyp' => "Enum('Keskkyte, Elekter')",
	'Kyttetyyp' => "Enum('Keskkyte, Elekter, Puukyte')",
	'Tubadearv' => "Enum('1, 2, 3, 4,5,rohkem')",
        'Krundisuurus' => 'Text',
	'Yldpind' => 'Text',
	'Korrus' => 'Text',
	'Vannitube' => 'Text',
	'Tualette' => 'Text',
	'Aadress' => 'Text',
      	'Linn' => 'Text',
	'Vald' => 'Text',
	'Maakond' => 'Text'
	); 
	static $has_one = array ( 
	'Nimekiri' => 'Nimekiri',
	'Photo' => 'Image'
	); 
	static $has_many = array (
	'GalleryImages' => 'GalleryImage' 
	);
	static $searchable_fields = array( 
		'Elamutyyp' => 'ExactMatchFilter', 
		'Yldpind' => 'ExactMatchFilter', 
		'Linn' => 'ExactMatchFilter', 
		'Tubadearv' => 'ExactMatchFilter' 
	);
	public function getCMSFields_forPopup() 
	{ 
	return new FieldSet( 
		new TextField('Objektinimi'), 
		new SimpleWysiwygField('Kirjeldus'), 
		new DropdownField(
		'Elamutyyp',
		'Elamutyyp', 
		singleton('Objekt')->dbObject('Elamutyyp')->enumValues()),
		new DropdownField(
		'Soojaveetyyp',
		'Soojaveetyyp', 
		singleton('Objekt')->dbObject('Soojaveetyyp')->enumValues()),
		new DropdownField(
		'Kyttetyyp',
		'Kyttetyyp', 
		singleton('Objekt')->dbObject('Kyttetyyp')->enumValues()),
		new TextField('Hind'),
        	new TextField('Krundisuurus'),
        	new TextField('Yldpind'),
			new DropdownField(
		'Tubadearv',
		'Tubadearv', 
		singleton('Objekt')->dbObject('Tubadearv')->enumValues()),
        	new TextField('Korrus'),
        	new TextField('Vannitube'),
        	new TextField('Tualette'),
		new ImageField('Photo'),
		new TextField('Aadress'),
        	new TextField('Linn'),
        	new TextField('Vald'),
        	new TextField('Maakond'),
        	new ImageDataObjectManager( 
		$this, 
		'GalleryImages', // Source name
         	'GalleryImage', // Source class
         	'MyGalleryImage', // File name on DataObject
		array('Pildinimi' => 'Pildinimi')) 
		);
}
public function getCustomSearchContext() { 
      $fields = $this->scaffoldSearchFields(array('Elamutyyp','Yldpind','Linn','Tubadearv') 
      ); 
      $filters = array( 
         'Elamutyyp' => new ExactMatchFilter('Elamutyyp'), 
         'Yldpind' => new ExactMatchFilter('Yldpind'), 
         'Linn' => new ExactMatchFilter('Linn'), 
         'Tubadearv' => new ExactMatchFilter('Tubadearv') 
      ); 
      return new SearchContext( 
         $this->class, 
         $fields, 
         $filters 
      ); 
   } 
} 
?> 

Avatar
Webdoc

Community Member, 349 Posts

12 September 2010 at 4:08am

Edited: 12/09/2010 4:31am

Made it using example from EmployeePage and Employee
but on that code is not the page template .ss description

Some explaining also:
in the nimiekiri.php
Objekt = Realestate object
Objektinimi = The name of realestate object
Kirjeldus = The description of realestate object

in the objekt.php
Objektinimi = The name of realestate object
Kirjeldus = The description of realestate object
Hind = Realestate object price
Elamutyyp = The type of realestate object
Soojaveetyyp = The type of hotwater making in realestate object
Kyttetyyp = The type of heating in realestate object
Tubadearv = number of rooms in object 1-5 or more
Yldpind = Space in Realestate object
Objektinimi = The name of realestate object
Korrus = floor number
Vannitube = how many bathrooms
Tualette = how many toilets
Aadress, Linn, Vald, Maakond = the adress, city, region, state of the objekt

how i need them do work u can see on page http://www.vspalvelut.fi/uusweb/korterid/ (its made without dataobjects and is not filter searchable thats why i made the new one)

first there is the objectlist and when u click on object u can see the information.

like it do use like i made the earlier version what was without dataobjects.

Avatar
Martijn

Community Member, 271 Posts

12 September 2010 at 7:49pm

Avatar
Webdoc

Community Member, 349 Posts

12 September 2010 at 9:06pm

Edited: 12/09/2010 9:31pm

Tried it but maybe im too newbie to understand it.
If u understand maybe u can help me with this.

the function objektlist lets me show the titles, picture. but not the link to the objekt

Avatar
Webdoc

Community Member, 349 Posts

12 September 2010 at 10:34pm

Edited: 13/09/2010 12:13am

Need to show them like so:
nimekiri
objekt-1
objekt-2
objekt-3
nimekiri-2
objekt-1
objekt-2
objekt-3

and so on

Can someone please help me out

Avatar
Webdoc

Community Member, 349 Posts

13 September 2010 at 11:51pm

can u help me out Martijn

Avatar
Martijn

Community Member, 271 Posts

14 September 2010 at 1:46am

Edited: 14/09/2010 1:46am

Hi Webdoc,

This tutorial covers DataObject relations:

http://doc.silverstripe.org/tutorial:5-dataobject-relationship-management

In your case you can use something like this in a template

in Nimekiri.ss:

<% if Objektid %>
  <% control Objektid %>
    <h2>$Objektinimi</h2>
    $Kirjeldus
  <% end_control %>
<% end_if %>

Avatar
Webdoc

Community Member, 349 Posts

14 September 2010 at 3:02am

this i know but is there a way to show the whole objekt in in new page like objekt 1 in mysite.com/nimekiri/objekt1

Go to Top