在 Silverstripe CMS 中使用 Uploadify 将图像附加到页面

发布于 2024-12-15 22:39:52 字数 737 浏览 5 评论 0原文

我们希望使用 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 用户必须单击“选择现有”选项卡并选择/导入他们想要的图像。

我猜我们错过了一些非常非常简单的事情,任何帮助将不胜感激。

We want to use the Uploadify module so Silverstripe CMS users can simply upload images that are then attached to Pages. At the basic level this is the code:

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" 
       ); 

    }

However when a file is Uploaded through the "Upload New" tab it isn't automatically attached to the page. We thought this would be the default behaviour.

Instead CMS users have to click on the "Choose existing" tab and select/ Import the images they are after.

I'm guessing we've missed something very very simple, any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-12-22 22:39:52

你真的扩展了图像本身吗?这也许是可能的,但我一直使用 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 上的一些样式问题)。

Do you really extend the image itself? It might be possible, but I've always used a DataObject instead. So Page has_many PageImages, PageImage has_one Page and PageImage has_one Image.

See also http://deadlytechnology.com/silverstripe/silverstripe-image-gallery/ or https://github.com/xeraa/silverstripe-book/tree/master/chapter-07/module_gallery/code for complete examples. Note: Both use the DataObjectManager module.

And I second ryanwachtl's suggestion to split up the file (if you haven't done so and this is merely some styling issue on stackoverflow).

音盲 2024-12-22 22:39:52

这里只是猜测,但如果 Page.php 中定义了 PageImage 类,您可能需要将其更改为 Page_Image,以遵循 SilverStripe 约定。

Just a guess here, but if PageImage class is defined in Page.php you may want to change it to Page_Image, to follow SilverStripe conventions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文