2013-06-04 31 views
0

我遇到了果園問題。 我創建了一個小部件,是一個視頻播放器,這是一個簡單的小部件類ContentPartRecord:果園中的小部件不會保存到數據庫中

public class VideoPlayerPartRecord : ContentPartRecord 
    { 
     public virtual string MediaFile { get; set; } 
     public virtual int Width { get; set; } 
     public virtual int Height { get; set; } 
     public virtual bool AutoStart { get; set; } 
     public virtual bool Repeat { get; set; } 
    } 

和類ContentPart:

public class VideoPlayerPart : ContentPart<VideoPlayerPartRecord> 
     { 
      [Required(ErrorMessage = "Media File required")] 
      [Display(Name = "Media File: ")] 
      public string MediaFile 
      { 
       get { return Record.MediaFile; } 
       set { Record.MediaFile = value; } 
      } 

      [Required(ErrorMessage = "Width required")] 
      [Display(Name = "Width: ")] 
      public int Width 
      { 
       get { return Record.Width; } 
       set { Record.Width = value; } 
      } 

      [Required(ErrorMessage = "Height required")] 
      [Display(Name = "Height: ")] 
      public int Height 
      { 
       get { return Record.Height; } 
       set { Record.Height = value; } 
      } 

      [Display(Name = "Auto Start: ")] 
      public bool AutoStart 
      { 
       get { return Record.AutoStart; } 
       set { Record.AutoStart = value; } 
      } 

      [Display(Name = "Repeat: ")] 
      public bool Repeat 
      { 
       get { return Record.Repeat; } 
       set { Record.Repeat = value; } 
      } 
     } 

這是文件遷移:

public class Migrations : DataMigrationImpl { 

      public int Create() { 
       // Creating table default_Raise_VideoPlayer_VideoPlayePartRecord 
       SchemaBuilder.CreateTable("default_Raise_VideoPlayer_VideoPlayePartRecord", table => table 
        .ContentPartRecord() 
        .Column("MediaFile", DbType.String) 
        .Column("Width", DbType.Int32) 
        .Column("Height", DbType.Int32) 
        .Column("AutoStart", DbType.Boolean) 
        .Column("Repeat", DbType.Boolean) 
       ); 

       ContentDefinitionManager.AlterPartDefinition(typeof(VideoPlayerPart).Name, cfg => cfg 
        .Attachable()); 

       return 1; 
      } 

      public int UpdateFrom1() { 
       ContentDefinitionManager.AlterTypeDefinition("VideoPlayerWidget", cfg => cfg 
        .WithPart("VideoPlayerPart") 
        .WithPart("WidgetPart") 
        .WithPart("CommonPart") 
        .WithSetting("Stereotype", "Widget")); 

       return 2; 

      } 


     } 

問題是,當我插入小部件它被添加,但我看不到它。爲什麼??

+0

您是否還爲內容部分創建了一個處理程序和驅動程序類? – mdm

回答

1

您需要爲您的小部件添加一個Handler以持久保存項目,並使用placement.info條目來呈現它。

http://docs.orchardproject.net/Documentation/Writing-a-content-part

(從文章取代碼)

using Maps.Models; 
using Orchard.ContentManagement.Handlers; 
using Orchard.Data; 

namespace Maps.Handlers { 
    public class MapHandler : ContentHandler { 
     public MapHandler(IRepository<MapRecord> repository) { 
      Filters.Add(StorageFilter.For(repository)); 
     } 
    } 
} 

和Placement.info

<Placement> 
    <Place Parts_Map="Content:10"/> 
    <Place Parts_Map_Edit="Content:7.5"/> 
</Placement> 

如果它不保存到數據庫 - 它可能處理程序。如果它不顯示在屏幕上,它可能是placement.info

你也沒有提及有一個驅動程序或一個視圖,但我想這是處理程序或你失蹤的位置信息。此外,在關聯驅動程序,遷移和放置信息時,請仔細檢查拼寫和慣例,因爲如果您手動創建零件,有幾個地方可以使用錯誤的文本字符串。

相關問題