Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Getting a 404 when clicking the 'Add ...' button, but only one some page types

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1007 Views
  • jbryner
    Avatar
    Community Member
    15 Posts

    Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    I'm working on creating a "Call To Action" sidebar using DOM. The admin can select an button image and a page to link to inside the site. I want this to be available on all pages, so I'm making a 'Page' => 'Page relationship. Inside the SS admin though, when I'm editing a normal "Page" and I click the 'Add [Call To Action]' button, the lightbox popup shows a 404 page. Now, if I'm on a "Redirector" Page and try to add one there, I get the correct file upload page with the Upload files from my computer, Upload Files button, etc.

    The 404 url is http://localhost/admin/EditForm/field/CallToActions/upload

    Code below

    class CallToAction extends DataObject
    {
       static $db = array (
       );
       
       static $has_one = array (
          'CTAAttachment' => 'Image',
          'Page' => 'Page',
          'PageLink' => 'SiteTree'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Address'),
             new SimpleTreeDropdownField("LinkID", "Select a page to link to", "SiteTree"),
             new ImageField('CTAAttachment', 'CTA Image')
          );

       }
    }


    class Page extends SiteTree {
       
       public static $db = array(
          'SecondaryNav' => 'Boolean'
       );
       
       public static $has_one = array(
       );
       
    public static $has_many = array(
    'CallToActions' => 'CallToAction'
    );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
       
          $fields->addFieldToTab("Root.Behaviour", new CheckboxField("SecondaryNav", "Show In Secondary Menu"));
          
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'CallToActions', // Source name
             'CallToAction', // Source class
             'CTAAttachment', // File name on DataObject
             array(), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          
       $fields->addFieldToTab("Root.Content.CallsToAction",$manager);
           
        return $fields;
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    Could be a nested URLs issue. Are you on 2.4?

  • jbryner
    Avatar
    Community Member
    15 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    On version 2.3.4.

    Still somewhat fresh on SilverStripe dev... can you explain the nested URL issue a little more?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    Nested URLs is part of the 2.4 branch. It supports having hierarchical URLs, such as /staff/new-york/joe-person. The whole thing chucks a wobbly into the URL handling of Silverstripe, and I don't know that DOM is compliant as yet.

    I'm not sure about this one. You might want to try $manager->setParentClass("Page"); if you're going to be managing the relationship on descendant page types.

    What kind of 404 are you getting? A hard Apache 404? Or a friendly Silverstripe page?

  • jbryner
    Avatar
    Community Member
    15 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    It's a SS 404. I'll try out your suggestion and post the results.

  • jbryner
    Avatar
    Community Member
    15 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    Still no dice. Like I said, a page like a redirector is loading correct uploader inside the iframe. The weird thing is that on a "page", as in a "page" type, the iframe is getting the 404, even though the url the iframe is loading is the exact same as the src when it loads correctly. I can even open the iframe in a new window - from a "redirector" page the iframe opened in a new window opens fine, from a "page" I get the 404. Same URL.

    Can't for the life of me figure it out.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    Hi jbryner

    I copied your code over to my 2.3.4 and 2.3.5 install and it's working flawlessly in both releases. It works for Page and all other subclasses thereof.

    And: This has nothing to do with nested urls, these are regular CMS urls (as defined with Director::addRules), so no worries there.

    I can't tell what causes your issue. Maybe try the following:
    - run /dev/build?flush=all
    - recursively set the permissions of the assets folder to 777
    - try your code in another SilverStripe installation

  • jbryner
    Avatar
    Community Member
    15 Posts

    Re: Getting a 404 when clicking the 'Add ...' button, but only one some page types Link to this post

    Well, I moved that install to a different site and works fine. I'm guessing it was something with my development environment then. Granted, my dev environment is a bit different than a basic site in Apache. I'm still befuddled as to why it wasn't working, since it was hitting the same URL and working in one instance and not another. Oh well.

    Thanks for the help everyone!

    1007 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.