在Silverstripe CMS中上传图像到页面


Attach Image to Page with Uploadify in Silverstripe CMS

我们希望使用Uploadify模块,以便Silverstripe CMS用户可以简单地上传图像,然后附加到页面。在基本级别上,这是代码:

class Page extends SiteTree {
       static $has_many = array( 
         "PageImages" => "PageImage" 
      );
       function getCMSFields(){ 
          $fields = parent::getCMSFields(); 
          $fields->addFieldToTab("Root.Content.PageImages", new MultipleFileUploadField('PageImages','Add Images to Page'));       
          return $fields; 
       } 
    }
    class PageImage extends Image { 
       static $has_one = array( 
          "Page" => "Page" 
       ); 
    }

然而,当文件通过"上传新"选项卡上传时,它不会自动附加到页面。我们认为这是默认的行为。

相反,CMS用户必须点击"选择现有"选项卡并选择/导入他们想要的图像。

我猜我们遗漏了一些非常非常简单的东西,任何帮助都会很感激。

你真的扩展了图像本身吗?这可能是可能的,但我一直使用DataObject代替。所以Page has_many PageImages, PageImage has_one Page和PageImage has_one Image。

参见http://deadlytechnology.com/silverstripe/silverstripe-image-gallery/或https://github.com/xeraa/silverstripe-book/tree/master/chapter-07/module_gallery/code获得完整的示例。注意:两者都使用DataObjectManager模块。

和我第二ryanwachtl的建议拆分文件(如果你还没有这样做,这只是一些样式问题的stackoverflow)。

这里只是一个猜测,但是如果PageImage classPage.php中定义,您可能希望将其更改为Page_Image,以遵循SilverStripe约定。