Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » GridField "internal server error" on edit relation

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

Page: 1
Go to End
Author Topic: 1068 Views
  • richard-ward
    Avatar
    Community Member
    31 Posts

    GridField "internal server error" on edit relation Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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

    ?

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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!

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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!

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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!!

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: GridField "internal server error" on edit relation Link to this post

    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?

    1068 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.