Jump to:

7939 Posts in 1472 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: 2360 Views
  • Webdoc
    Avatar
    Community Member
    329 Posts

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

    In cms i make page using pagetype nimekri then i can add objekt's under it but in frontend i see only the listing i also need the full detail page mysite.com/nimekiri/someobjekt/

    that is the problem.

    is there any way to do that or what i need to change in my code to allow that.

  • Martijn
    Avatar
    Community Member
    271 Posts

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

    Well thats exactly what's this page is all about:

    http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page

    Especially from Part 3..

    Example for Nimekri.php . I did not test is, but something like this should work.

    <?php

    class Nimekri extends Page{
       
       // .....
       
       static $has_many = array (
          'Objektid' => 'Objekt'
       );
       
       // .....
    }

    class Nimekri_Controller extends Page_Controller{
       
       static $allowed_actions = array(
          'show'
       );
       
       function init(){
          parent::init();   
       }
       
       
       /**
        * In template
        * <% if show %>
        * <% control show %>
        * $Objektinimi
        * $Kirjeldus
        * <% end_control %>
        * <% end_if %>
        *
        */
       function show($request){
          if($request->param('ID')){
             $obj = DataObject::get_by_id('Objekt', (int)$request->param('ID'));
             return $this->customise($obj)->renderWith(array('Nimekri'));
          }
       }
    }

    class Objekt extends DataObject{
       
       // .....
       
       
       // Use this to link to a single Objekt
       function Link(){
          return $this->Nimekiri()->Link() .'show/'.$this->ID;   
       }
       
       
       // .....   
    }

  • Webdoc
    Avatar
    Community Member
    329 Posts

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

    Strange but i dont get it work
    used code:
    nimekiri.php

    <?php
    class Nimekiri extends Page
    {
    static $has_many = array (
    'Objektid' => 'Objekt'
    );
    static $allowed_actions = array(
    'show'
    );

    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 init(){
    parent::init();
    }
       function show($request){
        if($request->param('ID')){
    $obj = DataObject::get_by_id('Objekt', (int)$request->param('ID'));
    return $this->customise($obj)->renderWith(array('Nimekri'));
    }
    }
    }
    ?>


    objekt.php:

    <?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
             );
          }
          function Link(){
             return $this->Nimekiri()->Link() .'show/'.$this->ID;
          }
          
    }
    ?>


    and nimekiri.ss:

    <div class="typography">
    <h2>$Title</h2>
    <% if show %>
    <% control show %>
    <div class="pilt">
    <table width="300" border="0">
    <tr>
             <td><h4>$Objektinimi</h4></td>
    </tr>
    <tr>
    <td valign="top"><table width="300" height="130" border="0">
    <tr>
    <td width="130" align="left" valign="top"><a href="{$Top.URLSegment}/{$ID}" title="$Objektinimi">$Photo.SetWidth(120)</a></td>
    <td align="left" valign="top">
    <% if Hind %><span style="font-size:11px;"><% _t("MYYGIHIND","M&uuml;&uuml;gihind") %>:<strong>$Hind</strong></span><br /><% end_if %>
    <% if Yldpind %><span style="font-size:11px;"><% _t("YLDPIND","&Uuml;ldpind") %>: <strong>$Yldpind</strong></span><br /><% end_if %>
    <% if Krundisuurus %><span style="font-size:11px;"><% _t("KRUNT","Krundi suurus") %>: <strong>$Krundisuurus</strong></span><br /><% end_if %>
    <p style="font-size:11px;"><br /><a href="$link" title="$Objektinimi"><% _t("INFO","Detailne info") %></a></p></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </div>
    <% end_control %>
    <% end_if %>
    $Content
    $PageComments
    $Form
    <div class="clear"><!-- --></div>
    </div>
    <div style="margin-bottom:20px;"></div>

  • UncleCheese
    Avatar
    4085 Posts

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

    What does that mean? "Can't get it to work"?

    You need to describe the problem you're having in order for us to help you.

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • Martijn
    Avatar
    Community Member
    271 Posts

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

    static $allowed_actions = array(
    'show'
    );

    needs to be in your controller

  • Webdoc
    Avatar
    Community Member
    329 Posts

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

    but it on nimekiri.php in controler fisrt before function init(){
    parent::init();
    }
    but then it doesnt show anything in mysite/nimekiri/

  • Martijn
    Avatar
    Community Member
    271 Posts

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

    If you want to display the object, you need to access it with www.yoursite.com/nimekiripageurl/show/23 (ObjektID)

    I really advise you to play with the tutorial on SSBits. Easier then that you probably won't get..

    http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page

    There is a download with the complete files you can use as an example:

    http://www.ssbits.com/assets/Uploads/AttachedFiles/AttachedFiles/CompletedfilesURLParams.zip

  • Webdoc
    Avatar
    Community Member
    329 Posts

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

    nothing i gonna show up not in main page and also not in objekt place to i need to make some new template under layout like objekt.ss

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