質問

I'm pretty much setting up the tutorial 5 Mentor section as I site I'm building has teachers, so exact same concept.

When I go to link a mentor from a page, when I search the the text field, the results I get don't show the first name field, they show the dataobject id #.

My fields are FistName and LastName on the dataobject and on the dataobject I've setup $searchable_fields & $summary_fields to match these columns, yet I still get the results above.

Also, my search field to start shows this. Notice the 'partial match' in the placeholder text. Shouldn't it just show the field name?

Using 3.1 and basically just copied and pasted tutorial 5 for the mentors part. The tutorial seems to work right out of the box, so what am I missing?

役に立ちましたか?

解決

Title is the default display value for pretty much any basic presentation of a DataObject in the CMS. But not all DataObjects have a Title, so the class DataObject has a method getTitle() which returns "#{$this->ID}.

there are 2 ways to solve your problem:

  1. overwrite getTitle() in your DataObject (the Mentor)

    public function getTitle() {
        return "{$this->Firstname} {$this->Lastname}";
    }
    
  2. tell the search field thingy on the GridField to use something else than title (example code according to the tutorial)

    class Project extends Page {
        public function getCMSFields() {
            $config = new GridFieldConfig_RelationEditor();
            $autoCompleteComponent = $config->getComponentByType('GridFieldAddExistingAutocompleter');
            $autoCompleteComponent->setResultsFormat('$FirstName $LastName');
            $mentorsField = new GridField(
                'Mentors',
                'Mentors',
                $this->Mentors(),
                $config
            );           
            $fields->addFieldToTab('Root.Mentors', $mentorsField);
            return $fields;
        }
    }
    
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top