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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

[SOLVED] Fatal error: Call to undefined method


Go to End


6 Posts   2352 Views

Avatar
sebastiankozub

Community Member, 59 Posts

15 October 2015 at 8:56am

Edited: 15/10/2015 9:41am

Hello,

I'd like to create a grid that will allow me to add some photos with names to general configuration (Settings Tab).
So I followed many tutorials and in every of them they use the schema that does not work for me.

I get Fatal error: Call to undefined method GostcompSiteConfig::CooperativesLogoImages() in C:\wamp\www\gostcomp\mysite\code\GostcompSiteConfig.php on line 27. when I try to get to /admin/settings.
Dev/Build success without errors...

Below I show the GostcompSiteConfig.php that looks like many others tutorials about gridfields...

class GostcompSiteConfig extends DataExtension {     
 
    public static $has_many = array(
        'CooperativesLogoImages' => 'CooperativePhoto',		
    );

    public static $db = array(			
        //'FacebookURL' => "Varchar(250)",
        //'VimeoURL' => "Varchar(250)",				
    );

    public function updateCMSFields(FieldList $fields) {
        //$fields->addFieldToTab("Root.CooperativesLogos", new UploadField("CooperativesLogoImages", _t('GostcompSiteConfig.LogosForYourCooperatives', "Zdjęcia (loga) partnerów")));
        
        $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
            new GridFieldDeleteAction('unlinkrelation')
        );
        
        $fields->addFieldToTab("Root.CooperativesLogos", new GridField("CooperativesLogoImages", "CooperativePhoto", $this->CooperativesLogoImages(), $gridFieldConfig));
        //$fields->addFieldToTab("Root.Main", new TextField("FacebookURL", "Enter the full URL of your Facebook page"));	 
        //$fields->addFieldToTab("Root.Main", new TextField("VimeoURL", "Enter the full URL of your Vimeo page"));	
    }
}

class CooperativePhoto extends DataObject
{
    public static $db = array(
        'Name' => 'Varchar',
    );
    
    public static $has_one = array(        
        'Photo' => 'Image',
        'SiteConfig' => 'SiteConfig'
    );
    
    // Summary fields 
    public static $summary_fields = array('Thumbnail'=>'Thumbnail','Name'=>'Name');
    public function getThumbnail()
    { 
        return $this->Image()->CMSThumbnail(); 
    }
    
    public function getCMSFields_forPopup() 
    { 
        // Profile picture field
        $thumbField = new UploadField('Photo', 'Photo (transparent background suggested)');
        $thumbField->allowedExtensions = array('png');

        // Name, Description and Website fields
        return new FieldList(
            new TextField('Name', 'Name'),
            //new TextareaField('Description', 'Contact description'),
            //new TextField('Website', 'Website URL (including http://)'),
            $thumbField
        );
    }
}

Finally I add this extension to SiteConfig in _config.php file

Object::add_extension('SiteConfig', 'GostcompSiteConfig');

Avatar
helenclarko

Community Member, 166 Posts

15 October 2015 at 9:50am

Edited: 15/10/2015 9:57am

Hi Sebastiankozub,

Can you post up both your GostcompSiteConfig.php and CooperativePhoto.php files?

However before doing that, try a /dev/build/?flush=1

I cant see much wrong with your code, however if that is your entire GostSiteConfig.php file It's missing the opening "<?php" tag.

EDIT: I think I've found your issue. Your extension needs to be the following:

_config.php

SiteConfig::add_extension('GostcompSiteConfig');

-helenclarko

Avatar
sebastiankozub

Community Member, 59 Posts

15 October 2015 at 9:58am

Nothing of the mentioned solutions:
1. dev/build?flush=1 works perfect - no error
2. <?php is present
3. When change updateCMSfields to getCMSfields and return them do not get Fatal Error but then I cannot see any new tab in settings.

I have no CooperativePhoto.php file, CooperativePhoto class is defined in GostcompSiteConfig.php
I think you are smart and help me :(

Avatar
helenclarko

Community Member, 166 Posts

15 October 2015 at 10:00am

Edited: 15/10/2015 10:01am

Hi Sebastiankozub,

I have edited my previous post:

EDIT: I think I've found your issue. Your extension needs to be the following:

_config.php

SiteConfig::add_extension('GostcompSiteConfig');

Then dev/build?flush=1

-helenclarko

Avatar
sebastiankozub

Community Member, 59 Posts

15 October 2015 at 7:21pm

Edited: 15/10/2015 8:37pm

No change, still the same fatal error when usping updateCMSfields and no change in Settings tab when using getCMSfields in class GostcompSiteConfig.

I think the problem is that framework cannot generate list of CooperativesLogoImages and then there is no $this->CooperativesLogoImages() function in SiteConfig.
1. Maybe this is caused by Image (without relation) in CooperativesPhoto?
2. Maybe this is cause by that I use DataExtension?
3. Maybe this caused by that it is not the SiteConfig extending, but the class is added as extension?

I have lack of knowledge in SS framework. Maybe someone the ideas above will give someone some "eureka" :)

Avatar
sebastiankozub

Community Member, 59 Posts

16 October 2015 at 7:48am

SOLUTION

$fields->addFieldToTab("Root.CooperativesLogos", new GridField("CooperativesLogoImages", "CooperativePhoto", new DataList('CooperativePhoto'), $gridFieldConfig));