SilverStripe - 显示特定于一页的数据对象
我对 SilverStripe 还很陌生,所以如果这看起来很简单,请原谅我。我搜索了论坛并阅读了文档,但看不到我想要的内容。
我正在使用 dataobjectmanager 将幻灯片图像添加到页面。如果我使用幻灯片图像创建一个页面,然后从相同的页面类型创建一个新页面,则幻灯片图像已填充第一页中的图像。我猜它们被添加为全球资产?
有没有一种方法可以使用 dataobjectmanager 将对象添加到一个页面?
这是我的幻灯片/数据对象代码...
<?php
class Slide extends DataObject {
/**
*
* DB fields
* @var unknown_type
*/
static $db = array (
'Title' => 'Varchar(255)',
'Text' => 'Text',
'Link' => 'Text'
);
/**
*
* Relations
* @var array
*/
static $has_one = array (
'HomePage' => 'HomePage',
'Image' => 'Image'
);
/**
*
* /Fields to show in the DOM table
* @var array
*/
static $summary_fields = array(
'Thumb' => 'Image',
'Title' => 'Title',
'Text' => 'Text',
'Page link' => 'Link'
);
/**
* (non-PHPdoc)
* @see httpdocs/sapphire/core/model/DataObject::getCMSFields()
*/
public function getCMSFields()
{
return new FieldSet(
new TextField('Title'),
new TextField('Text'),
new TextField('Link'),
new ImageField('Image', 'Image', null, null, null, 'slides')
);
}
/**
*
* Generate our thumbnail for the DOM
*/
public function getThumb()
{
if($this->ImageID)
return $this->Image()->CMSThumbnail();
else
return '(No Image)';
}
}
这是我的页面代码
<?php
class AwardsHolder extends Page {
static $db = array(
);
static $has_many = array(
'Slides' => 'Slide',
'Spotlights' => 'Spotlight'
);
static $allowed_children = array('ArticlePage');
public function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'Slides',
'Slide'
);
$fields->addFieldToTab("Root.Content.Slideshow", $manager);
$manager = new DataObjectManager(
$this,
'Spotlights',
'Spotlight'
);
$fields->addFieldToTab("Root.Content.Spotlights", $manager);
$fields->removeFieldFromTab("Root.Content.Main", 'Content');
return $fields;
}
}
class AwardsHolder_Controller extends Page_Controller {
}
I'm fairly new to SilverStripe so please forgive me if this seems simple. I've had a search of the forum and read the documentation but couldn't see what I'm after.
I'm using the dataobjectmanager to add slideshow images to a page. If I create one page with slideshow images and then create a new page from the same page type, the slideshow images are already populated with the ones from the first page. I guess they're added as global assets?
Is there a way to add objects to just one page with the dataobjectmanager?
This is my slide/dataobject code...
<?php
class Slide extends DataObject {
/**
*
* DB fields
* @var unknown_type
*/
static $db = array (
'Title' => 'Varchar(255)',
'Text' => 'Text',
'Link' => 'Text'
);
/**
*
* Relations
* @var array
*/
static $has_one = array (
'HomePage' => 'HomePage',
'Image' => 'Image'
);
/**
*
* /Fields to show in the DOM table
* @var array
*/
static $summary_fields = array(
'Thumb' => 'Image',
'Title' => 'Title',
'Text' => 'Text',
'Page link' => 'Link'
);
/**
* (non-PHPdoc)
* @see httpdocs/sapphire/core/model/DataObject::getCMSFields()
*/
public function getCMSFields()
{
return new FieldSet(
new TextField('Title'),
new TextField('Text'),
new TextField('Link'),
new ImageField('Image', 'Image', null, null, null, 'slides')
);
}
/**
*
* Generate our thumbnail for the DOM
*/
public function getThumb()
{
if($this->ImageID)
return $this->Image()->CMSThumbnail();
else
return '(No Image)';
}
}
This is my page code
<?php
class AwardsHolder extends Page {
static $db = array(
);
static $has_many = array(
'Slides' => 'Slide',
'Spotlights' => 'Spotlight'
);
static $allowed_children = array('ArticlePage');
public function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'Slides',
'Slide'
);
$fields->addFieldToTab("Root.Content.Slideshow", $manager);
$manager = new DataObjectManager(
$this,
'Spotlights',
'Spotlight'
);
$fields->addFieldToTab("Root.Content.Spotlights", $manager);
$fields->removeFieldFromTab("Root.Content.Main", 'Content');
return $fields;
}
}
class AwardsHolder_Controller extends Page_Controller {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的关系中,您已指定
Slide
has_oneHomePage
,但它应该是AwardsHolder
。我首先会看看这个。In your relationships you have specified that a
Slide
has_oneHomePage
, but it should beAwardsHolder
. I'd start by looking at that first.