Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager Code Examples for the Frontend

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: 1137 Views
  • cardinale
    Avatar
    Community Member
    23 Posts

    DataObjectManager Code Examples for the Frontend Link to this post

    Hallo,
    I'm looking for an Code Example to integrate DOM in the Frondend.

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager Code Examples for the Frontend Link to this post

    I don't know that it will work, but you can give it a try. The only difference between a CMS form and a frontend form is that you can't pass the controller as $this. You'll have to pass it an instance of the holder object for the records you're managing. But there are a lot of other things to consider like javascript dependencies that will probably trip it up.

    It's definitely in my plans to make a frontend safe DOM, though.

  • cardinale
    Avatar
    Community Member
    23 Posts

    Re: DataObjectManager Code Examples for the Frontend Link to this post

    I tried it like this:

    public   function NachrichtenField() {

          $AerzteTable = new DataObjectManager(
                      $this,
                      'Testimonials',
                      'Nachricht',
                      array('ID' => 'ID'),
                      null
                   );
          $AerzteTable->setPermissions(array());
          $AerzteTable->setCustomSourceItems($this->Nachrichten);

          $Felder = new FieldSet( $AerzteTable );
          $Action = new FieldSet(new FormAction("Weiterleitung", 'hallo', 'Modifica Informazioni Utente - Indirizzo commerciale') );
          return new Form($this, "NacchrichtenField", $Felder, $Action);
       }

    But I want only a nice table, without other formelemements like the submit button.
    - The "Show results per page" doesn't work
    - The "Search" doesn't work

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager Code Examples for the Frontend Link to this post

    What is $this in that function?

  • cardinale
    Avatar
    Community Member
    23 Posts

    Re: DataObjectManager Code Examples for the Frontend Link to this post

    here the code, I put $this just because i don't know what to put else. is there a way to get working the search function or to switch it off?

    <?php
    class NachrichtenPage extends Page {

       public function getNachrichten() {
          $MemberID = Member::currentUserID();
             $auslese = DataObject::get('Nachricht', 'DepositaerID = "'.$MemberID.'" AND (Status = "NEU" OR Status = "GELESEN")' );
       return $auslese;
       }   
       
    }

    class NachrichtenPage_Controller extends Page_Controller {
       
    public   function NachrichtenField() {

          $AerzteTable = new DataObjectManager(
                      $this,
                      'Testimonials',
                      'Nachricht',
                      array('ID' => 'ID', 'Created' => 'Datum','Title'=> 'Betreff', 'Status' => 'Status',),
                      null
                   );
          $AerzteTable->setPermissions(array());
          $AerzteTable->setCustomSourceItems($this->Nachrichten);
          $AerzteTable->per_page_map = array('10');
          $AerzteTable->use_view_all = false;
          

          $Felder = new FieldSet( $AerzteTable );
          $Action = new FieldSet(new FormAction($this, 'hallo') );
          $myForm = new Form($this, "NacchrichtenField", $Felder, $Action);
          $myForm->getValidator()->setJavascriptValidationHandler('none');
          return $myForm;
       }

       
    }

    ?>

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: DataObjectManager Code Examples for the Frontend Link to this post

    I've been looking into this too, and I've had some luck generating something that works, but it isn't perfect.

    @cardinale: you could try DataObject::get('Nachricht', 'DepositaerID = "'.$MemberID.'" AND (Status = "NEU" OR Status = "GELESEN")' ); or possibly $this->getNachtrighten() instead of $this.

    @UncleCheese: It works somewhat for DataObjects, if I try to include objects based on SiteTree I get the error:

       public function ProjectsTable() {
    // Works
          $table = new DataObjectManager(DataObject::get("Source"), "Sources", "Source", array('Title' => 'Title'), "getCMSFields_forPopup");
    // Fails with error
    //      $projects = DataObject::get("Page");
    //      $table = new DataObjectManager($projects, "Pages", "Page", array('Title' => 'Title'), "getCMSFields_forPopup");
    $table->setPermissions(array());

          $fields = new FieldSet( $table );
          $Action = new FieldSet(new HiddenField($this, 'No button') );
          $myForm = new Form($this, "ProjectsTable", $fields, $Action);
          $myForm->getValidator()->setJavascriptValidationHandler('none');
          return $myForm;
       }

    [User Error] Couldn't run query: SELECT COUNT(DISTINCT SiteTree.ID) AS TotalCount FROM `SiteTree_Live` LEFT JOIN `Page_Live` ON `Page_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `BlogEntry_Live` ON `BlogEntry_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `BlogHolder_Live` ON `BlogHolder_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `DonationPage_Live` ON `DonationPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `ContactPage_Live` ON `ContactPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Expert_Live` ON `Expert_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `FeaturedPage_Live` ON `FeaturedPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Project_Live` ON `Project_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Region_Live` ON `Region_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Species_Live` ON `Species_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `ErrorPage_Live` ON `ErrorPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `RedirectorPage_Live` ON `RedirectorPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `VirtualPage_Live` ON `VirtualPage_Live`.ID = `SiteTree_Live`.ID WHERE (`SiteTree_Live`.ClassName IN ('Page','BlogEntry','BlogHolder','DonationPage','ContactPage','CountriesHolder','Expert','ExpertsHolder','Family','FeaturedHolder','FeaturedPage','Project','ProjectDOM','ProjectsHolder','Region','RegionsHolder','Species','TestimonialPage','ErrorPage','RedirectorPage','VirtualPage','AgendaHolder')) Unknown column 'SiteTree.ID' in 'field list'
    GET /largeherbivore.org/new-projectdom?stage=LIVE

    Line 401 in G:\localhost\largeherbivore.org\sapphire\core\model\MySQLDatabase.php

    It looks to me that the FROM table isn't passed the Live / staging attribute as the error doesn't occur when I look at the staging site. Clicking on the labels in the table didn't sort the column but resulted in a blank pages featuring the text 'mysite'.

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