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.

Customising the CMS /

GridField "internal server error" on edit relation


Reply


7 Posts   1406 Views

Avatar
richard-ward

Community Member, 31 Posts

22 August 2012 at 2:53am

Hi,

Firstly a disclaimer - what I am trying to do may well not be possible, but I thought I would check just in case...

I am trying to make a generic means of tagging objects in my SS3 application. The idea is that on any given page, I can pull together any related content based on tags. E.g. If a Page has tags for "apple", and i have some Files that have been tagged with "apple" then I will be able to display links to / the image on the Page. I am trying to do this with some generic configuration.

So far I have done the following:

Tag.php

<?php

class Tag extends DataObject {
   static $db = array(
      "Name" => "Varchar(25)"
   );

   static $belongs_many_many = array(
      "Taggables" => "Taggable"
   );

   // The summary fields to be used in GridField's etc.
   static $summary_fields = array(
      'Name' => 'Name'
   );
}

Taggable.php

<?php

class Taggable extends DataExtension {
   static $many_many = array(
      "Tags" => "Tag"
   );

   function updateCMSFields(FieldList $fields) {
      $tags = GridField::create('Tags', 'Some tags', $this->owner->Tags(), new GridFieldConfig_RelationEditor());
      $fields->push($tags);
   }
}

_config.php

Object::add_extension("File", "Taggable");
Object::add_extension("Page", "Taggable");

To an extent, the above works. The data model has been created so that there is a Tag table, and then Page_Tag and File_Tag tables. This seems perfectly reasonable. The GridField also appears on both the Page and File editing screens. I am able to add new Tags and link to existing Tags, but I get an internal server error when I edit the Tag. (Note - I do get an error on adding tags, but that is just because the url changes to edit - the data is inserted into the tables as expected).

It is just a browser Server Error page, rather than an SS templated screen, and I've been unable to locate any logs, so I really don't know what the cause of the issue is.

As I have said before, maybe it is just not possible, and I have been lucky to get this far, but I thought I'd see to see if anyone else has tried to merge together DataExtensions and GridFields.

Any help gratefully received.

Avatar
swaiba

Forum Moderator, 1798 Posts

22 August 2012 at 5:20am

It is just a browser Server Error page, rather than an SS templated screen, and I've been unable to locate any logs, so I really don't know what the cause of the issue is.

Have you gone through...

http://doc.silverstripe.org/framework/en/installation/common-problems

and

http://doc.silverstripe.org/framework/en/topics/debugging

?

Avatar
richard-ward

Community Member, 31 Posts

22 August 2012 at 7:09am

Edited: 22/08/2012 7:09am

Hi, yes I had read those pages. I have my environment set to be Dev and also configured to send errors to email.

Regards
Richard

Avatar
swaiba

Forum Moderator, 1798 Posts

22 August 2012 at 7:57am

are you familiar with the network tab in chrome (if you press F12 and switch to network and try the same action) where it reports the errors?

this is also good...

ini_set('display_errors', 1);error_reporting(E_ALL);

then there are apache logs (don't know the IIS equvilent)

in short there is always an answer even if you have to resort to using var_dump and die statement creeping forward or dividing by conquering.

hope you find the bug and crunch it!

Avatar
richard-ward

Community Member, 31 Posts

22 August 2012 at 8:26am

Excellent - thank you so much. I now know that the error is:

Fatal error: Call to undefined method Taggable::stat()

Now to find out why that is, and whether anything can be done about it!

Avatar
richard-ward

Community Member, 31 Posts

22 August 2012 at 9:28am

Ok, so "stat" is a function on Object, but DataExtension's do not extend Object, which makes sense given it is an extension. I assume it really needs to call stat on "owner", but not sure how to achieve that. Maybe I'm just taking the framework a step too far!!

Avatar
richard-ward

Community Member, 31 Posts

22 August 2012 at 11:54pm

Edited: 22/08/2012 11:56pm

I have resolved my issue - although I would be interested in an explanation why what I have done is ok...

I have removed the following from Tag.php:

static $belongs_many_many = array(
"Taggables" => "Taggable"
);

I did this as a hunch having thought, if I were adding a load of images to a page, I would put in the $has_many in Page, but I would not do anything to Image. Therefore, I thought, I could put $many_many into Taggable but not bother with $belongs_many_many in Tag, and hey presto, it worked - I can now add, link existing, edit and delete tags across multiple pages & files.

I can see this now avoids the issue of calling stat on Taggable when a Tag is being loaded, as it doesn't know to look for another object. But my question would be, what is the benefit of ever using $belongs_many_many?