在模板中输出DataObjectManager包括

时间:2012-06-18 03:13:30

标签: php silverstripe

我已按照此处的教程http://doc.silverstripe.org/old/modules:dataobjectmanager在CMS中创建了一个dataobjectmanager。

这一切都完美无缺,但是我在模板中输出它时遇到了问题。我的代码如下

<?php 
class InfoArea extends DataObject{ 
   static $db = array( 
      'Title' => 'Varchar(255)', 
      'Content' => 'HTMLText' 
   ); 

   static $has_one = array( 
      'ResortPage' => 'ResortPage' 
   ); 

   public function getCMSFields_forPopup(){ 
      return new FieldSet( 
         new TextField('Title'), 
         new SimpleTinyMCEField('Content') 
      ); 
   } 
}

ResortPage.php

....... 
static $has_many = array ( 
      "InfoAreas" => "InfoArea" 
   ); 
....... 
$fields->addFieldToTab("Root.Content.AdditionalInformation", 
         new DataObjectManager( 
         $this, 
         'InfoAreas', 
         'InfoArea', 
         array('Title' => 'Title','Content'=>'Content'), 
         'getCMSFields_forPopup' 
      )); 
........

我有一个模板“ResortPage.ss”,其中包含“ResortInfo.ss”。它来自这个包含文件,我需要输出DataObject。

我已经尝试过以下但是它没有输出任何内容

<% control InfoArea %> 
   $Title 
   $Content 
<% end_control %>

我在这里做错了什么?

由于

1 个答案:

答案 0 :(得分:0)

我找到了这个问题。在ResortPage课程中我有

static $has_many = array ( 
      "InfoAreas" => "InfoArea" 
   ); 

以及

static $has_one = array ( 
      "InfoAreas" => "InfoArea" 
   ); 

..错误。我只需要has_many