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.

Data Model Questions /

summary fields dont work for me.


Reply


5 Posts   1482 Views

Avatar
madmaurice

Community Member, 20 Posts

21 November 2010 at 6:00am

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?

Avatar
rob.s

Community Member, 78 Posts

22 November 2010 at 8:46pm

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

Avatar
madmaurice

Community Member, 20 Posts

23 November 2010 at 6:29am

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.

Avatar
rob.s

Community Member, 78 Posts

23 November 2010 at 6:43am

Edited: 23/11/2010 7:13am

sorry, didn't see it

It has to be this way:

static $summary_fields = array('Titel');

Rob

Avatar
Ingo

Forum Moderator, 801 Posts

15 December 2010 at 9:47pm

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