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.

All other Modules /

Discuss all other Modules here.

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

GridField Error


Go to End


22 Posts   2836 Views

Avatar
RobboNoCash

Community Member, 33 Posts

10 June 2015 at 3:24pm

Hi

There is something wrong with the GridField code in this module, can you please help me try and fix it?

Thanks

<?php
class Home extends Page {
private static $db = array(
'ContentHeader' => 'Text',
'ContentTwoHeader' => 'Text',
'ContentTwoContent' => 'Text',
'ContentThreeHeader' => 'Text',
'ContentThreeContent' => 'Text',
'ContentFourHeader' => 'Text',
'ContentFourContent' => 'Text',
'ContentFiveHeader' => 'Text',
'ContentFiveContent' => 'Text',
'ContentSixHeader' => 'Text',
'ContentSixContent' => 'Text'

);

public static $has_many = array (
'SliderPicture' => 'HomeSlider'
);

public function getCMSFields() {
$f = parent::getCMSFields();

$config = GridFieldConfig_RecordEditor::create();

$sliders = new GridField("SliderPicture", "SliderPicture", $this->SliderPicture(), $config);
$f->addFieldToTab('Root.Events', $sliders);

$f->addFieldToTab('Root.Main', new TextField('ContentHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentTwoHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentTwoContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentThreeHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentThreeContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFourHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFourContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFiveHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFiveContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentSixHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentSixContent'), 'Content');

return $f;

}

}

class Home_Controller extends Page_Controller {

public function init() {
parent::init();
}

}

<?php
class HomeSlider extends DataObject
{
public static $db = array(
'Title' => 'Text',
'Button' => 'Text',
'LinkSite' => 'Text'

);

public static $has_one = array(
'Picture' => 'Image'
);

public function getCMSFields() {
$f = new FieldList();

$f->push( new TextField('Title', 'Title for the slider') );
$f->push( new TextField('Button', 'Button for the slider') );
$f->push( new TextField('LinkSite', 'Link for the slider picture') );
$f->push( new UploadField('Picture', 'Image file'));

return $f;
}
}
?>

Avatar
tomjohn

Community Member, 19 Posts

10 June 2015 at 10:01pm

Edited: 10/06/2015 10:03pm

Try:

<?php
class Home extends Page {
private static $db = array(
'ContentHeader' => 'Text',
'ContentTwoHeader' => 'Text',
'ContentTwoContent' => 'Text',
'ContentThreeHeader' => 'Text',
'ContentThreeContent' => 'Text',
'ContentFourHeader' => 'Text',
'ContentFourContent' => 'Text',
'ContentFiveHeader' => 'Text',
'ContentFiveContent' => 'Text',
'ContentSixHeader' => 'Text',
'ContentSixContent' => 'Text'

);

public static $has_many = array (
'HomeSlider' => 'HomeSlider'
);

public function getCMSFields() {
$f = parent::getCMSFields();

$config = GridFieldConfig_RecordEditor::create();

$sliders = new GridField("SliderPicture", "SliderPicture", $this->SliderPicture(), $config);
$f->addFieldToTab('Root.Events', $sliders);

$f->addFieldToTab('Root.Main', new TextField('ContentHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentTwoHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentTwoContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentThreeHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentThreeContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFourHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFourContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFiveHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentFiveContent'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentSixHeader'), 'Content');
$f->addFieldToTab('Root.Main', new TextField('ContentSixContent'), 'Content');

return $f;

}

}

class Home_Controller extends Page_Controller {

public function init() {
parent::init();
}

}

<?php
class HomeSlider extends DataObject
{
public static $db = array(
'Title' => 'Text',
'Button' => 'Text',
'LinkSite' => 'Text'

);

public static $has_one = array(
'Picture' => 'Image',
'Home'	=>	'Home'
);

public function getCMSFields() {
$f = new FieldList();

$f->push( new TextField('Title', 'Title for the slider') );
$f->push( new TextField('Button', 'Button for the slider') );
$f->push( new TextField('LinkSite', 'Link for the slider picture') );
$f->push( new UploadField('Picture', 'Image file'));

return $f;
}
}
?>

If it didn't help add to _config.php

ini_set("log_errors", "On");
ini_set("error_log", "/");
if(!Director::isDev()) {
    // log errors and warnings
    SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-warnings.log'), SS_Log::WARN, '<=');

    // or just errors
    SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR);

    // or notices (e.g. for Deprecation Notifications)
    SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-notices.log'), SS_Log::NOTICE);
}

and check an error file in the main site folder. Good luck.

Avatar
RobboNoCash

Community Member, 33 Posts

12 June 2015 at 4:59pm

Thanks for your post
No that did not work either.
If anyone can please help me fix the error in this code I would be very grateful
Please look at my code and help me

Thanks
Robert

Avatar
Pyromanik

Community Member, 419 Posts

12 June 2015 at 11:53pm

The code looks fine.
It might help if you tell us what the actual problem is.

Avatar
RobboNoCash

Community Member, 33 Posts

13 June 2015 at 12:10pm

Hi

Thanks for your response.
The code works right before I add the GridField code, then when I add the GridField code and I try and open it through the admin system, the screen goes blank.
I agree with you it looks correct and it is very frustrating, but it is not working.
If you could try and help me fix it I would appreciate it a lot?

Thanks
Robert

Avatar
Pyromanik

Community Member, 419 Posts

16 June 2015 at 9:54pm

Edited: 16/06/2015 9:58pm

Sounds like you have a syntax or other kind of fatal PHP level error.
Please check the error logs.
If nothing is displayed there (and this is a development site), ensure the site is set up to display errors (both php & silverstripe).

Also you probably want RelationEditor config, not RecordEditor.

Avatar
RobboNoCash

Community Member, 33 Posts

17 June 2015 at 1:28pm

Thanks for your response
Where are the error logs?
I tried to open the page in Chrome and I found a error message it is,

Server error
Sorry, there was a problem with handling your request

Does anyone know how to fix this?

Avatar
Pyromanik

Community Member, 419 Posts

17 June 2015 at 8:34pm

Edited: 17/06/2015 8:34pm

Wherever your PHP is configured to put it.
I can't answer that. If you've no experience in system administration, and are using a shared host, then you could ask them. If you have some kind of control panel (like plesk or cpanel) you might be able to view it through that. If you have your own host set up, then you should ask the ops team, or whoever set it up.
If all else fails, google might be able to help you.

As for Silverstripe logs, this isn't set up by default. However if you put your site into dev mode (see the docs on environment management) then the error will be displayed in the output (either on screen or the ajax response depending on how the request is made).

Once you find out what the error is, then we can help you solve it.

Go to Top