在kentico管理员中使用NewClassWizard

问题描述 投票:0回答:1

我想创建一个自定义页面,使我可以手动跟踪kentico在数据库中所做的每个数据修改我了解可以使用NewClassWizard通过代码实现它。但是完成后如何在Kentico管理员中使用它?我尝试从Page Type模块加载它,但是可以找到一种方法来指定我的自定义类这是正确的使用方式吗?该文档对此并不清楚感谢您的帮助

kentico
1个回答
0
投票

我建议创建一个global event handler以跟踪更改。虽然Kentico已经为您完成了很多此类跟踪,但是您可以将想要的任何特定事件专门添加为全局事件。这将处理在面向客户的公共网站,Kentico UI内以及任何Kentico API调用中所做的任何更改。

在您的自定义全局事件处理程序中,您可以根据对象和CRUD活动检查different types of events。例如这样的东西:

using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.DocumentEngine;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomInitializationModule))]

public class CustomInitializationModule : Module
{
    // Module class constructor, the system registers the module under the name "CustomInit"
    public CustomInitializationModule()
        : base("CustomInit")
    {
    }

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()
    {
        base.OnInit();

        // Assigns custom handlers to events
        DocumentEvents.Insert.After += Document_Insert_After;
    }

    private void Document_Insert_After(object sender, DocumentEventArgs e)
    {
        if (e.Node.ClassName.ToLower() == "your.classname")
        {
            // create an event to log to a custom module table or a custom table so it's not logged directly in the Kentico Event log
            CustomTableItem item = new CustomTableItem("customtable.name");
            item.SetValue("ItemEventType", "Create document");
            item.SetValue("ItemEventCode", "Your event code");
            item.SetValue("ItemEventUserID", e.Node.DocumentModifiedByUserID);
            item.SetValue("ItemEventUrl", e.Node.NodeAliasPath);
            item.SetValue("ItemEventName", e.Node.DocumentName);
            item.Insert();
        }
    }
}

这是创建文档的简单示例。如果您不想,则不必检查页面类型的类名。您还可以为任何“对象”(例如cms_class对象)包括全局事件处理程序,只需在代码<name>Info.TYPEINFO.Events.<eventtype>中使用该定义即可。这不限于任何对象,您可以跟踪转换更新,页面类型字段修改等。您只需要知道对象名称/类型并在其周围编写代码即可。

© www.soinside.com 2019 - 2024. All rights reserved.