在 Silverstripe CMS 中使用 Uploadify 将图像附加到页面
我们希望使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你真的扩展了图像本身吗?这也许是可能的,但我一直使用 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).
这里只是猜测,但如果
Page.php
中定义了PageImage 类
,您可能需要将其更改为Page_Image
,以遵循 SilverStripe 约定。Just a guess here, but if
PageImage class
is defined inPage.php
you may want to change it toPage_Image
, to follow SilverStripe conventions.