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

时间:2011-11-15 22:46:21

标签: php uploadify silverstripe

我们希望使用Uploadify模块,因此Silverstripe CMS用户只需上传随后附加到Pages的图像即可。在基础级别,这是代码:

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用户必须单击“选择现有”选项卡,然后选择/导入他们所追踪的图像。

我猜我们错过了非常简单的事情,任何帮助都会受到赞赏。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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