Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » summary fields dont work for me.

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

Page: 1
Go to End
Author Topic: 1334 Views
  • madmaurice
    Avatar
    Community Member
    20 Posts

    summary fields dont work for me. Link to this post

    im currently using a modeladmin to manage a list of events

    because the result page only showed the id, i added a $summary_fields to my DataObject

       static $summary_fields = array(
          "Titel"=>"Titel"   
       );

    but when i now press Search i get an error

    Warning: "array_fill() [function.array-fill]: Number of elements must be positive" at line 743 of /var/www/example.com/page/cms/code/ModelAdmin.php

    i also tried

    function summaryFields() {
    return array("Titel"=>"Titel");
    }

    but this changed nothing

    any solutions for my problem?

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: summary fields dont work for me. Link to this post

    Hi,

    could you please provide the full Code of your Class.
    The static var is defined correctly. The error has to be somewhere else.

    Greets,
    Robert

  • madmaurice
    Avatar
    Community Member
    20 Posts

    Re: summary fields dont work for me. Link to this post

    VAAdmin:

    class VAAdmin extends ModelAdmin {
       public static $managed_models = array(
          'VAKategorie','VAEintrag'
       );
       
       static $url_segment = "va";
       static $menu_title = "Veranstaltungen";
    }

    VAEintrag:

    <?php

    class VAEintrag extends DataObject {
       static $db = array(
          "Titel"=>"Varchar(50)",
          "Kontakt"=>"Text",
          "Beschreibung" => "Text"
       );
       
       static $has_one = array(
          "Kategorie" => "VAKategorie"
       );
       
       function ShortenDesc($l=200) {
          $desc = $this->Beschreibung;
          if(strlen($desc) > $l) {
             return substr($desc,0,$l)."...";
          } else {
             return $desc;
          }
       }
       
       static $searchable_fields = array(
          "Titel",
          "Kontakt",
          "Beschreibung"
       );
          
       static $summary_fields = array(
          "Titel"=>"Titel"   
       );
          
       function getCMSFields() {
          $categories = DataObject::get('VAKategorie');
          if($categories) {
             $dropdowndata = $categories->toDropdownMap('ID','Titel','(Eine Kategorie aussuchen)',true);
          }   
       
          return new FieldSet(
             new TextField("Titel"),
             new TextareaField("Kontakt"),
             new TextareaField("Beschreibung"),
             new DropdownField("KategorieID","Kategorie",$dropdowndata)
          );
       }
    }

    here you are.

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: summary fields dont work for me. Link to this post

    sorry, didn't see it

    It has to be this way:

    static $summary_fields = array('Titel');

    Rob

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: summary fields dont work for me. Link to this post

    Your code example works for me with both array("Titel") and array("Titel" => "Titel") in 2.4.3

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