Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Need help to show dataobject on page

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4
Go to End
Author Topic: 2551 Views
  • Webdoc
    Avatar
    Community Member
    332 Posts

    Need help to show dataobject on page Link to this post

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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    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.

  • Martijn
    Avatar
    Community Member
    271 Posts
  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    can u help me out Martijn

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Need help to show dataobject on page Link to this post

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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    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

    2551 Views
Page: 1 2 3 4
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.