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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Reply


8 Posts   1082 Views

Avatar
jbryner

Community Member, 15 Posts

29 January 2010 at 5:55am

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;
   }
}

Avatar
UncleCheese

4085 Posts

29 January 2010 at 6:28am

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

Avatar
jbryner

Community Member, 15 Posts

29 January 2010 at 6:35am

On version 2.3.4.

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

Avatar
UncleCheese

4085 Posts

29 January 2010 at 9:49am

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?

Avatar
jbryner

Community Member, 15 Posts

29 January 2010 at 10:18am

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

Avatar
jbryner

Community Member, 15 Posts

2 February 2010 at 6:46pm

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.

Avatar
banal

Community Member, 901 Posts

2 February 2010 at 8:33pm

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

Avatar
jbryner

Community Member, 15 Posts

4 February 2010 at 7:47am

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!