SilverStripe - 显示特定于一页的数据对象

发布于 2024-12-10 01:41:06 字数 1992 浏览 0 评论 0原文

我对 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 技术交流群。

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

发布评论

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

评论(1

浸婚纱 2024-12-17 01:41:06

在您的关系中,您已指定 Slide has_one HomePage,但它应该是 AwardsHolder。我首先会看看这个。

In your relationships you have specified that a Slide has_one HomePage, but it should be AwardsHolder. I'd start by looking at that first.

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