Step by step teach you how to create ZKEACMS extension components/plug-ins and zkeacms extension Components

Source: Internet
Author: User

Step by step teach you how to create ZKEACMS extension components/plug-ins and zkeacms extension Components
Preface

If you do not know ZKEACMS, you may want to know about it first.

ASP. net mvc open-source website construction system ZKEACMS recommendation, from this site "fight"

Official Address: http://www.zkea.net/zkeacms

: Https://github.com/SeriaWei/ASP.NET-MVC-CMS/releases

GitHub: https://github.com/SeriaWei/ASP.NET-MVC-CMS

Open source Chinese community: http://git.oschina.net/seriawei/ASP.NET-MVC-CMS

Demo address: http://demo.zkea.net/

Background: http://demo.zkea.net/admin

Username and password: admin

Make a path navigation component:

 

Add a component project

Open the Modules directory (\ Easy. CMS. Web \ Modules) and find the Standard folder. This is a Standard component project. copy it and change the name to Breadcrumb.

Enter the Breadcrumb folder and change the project name to Easy. CMS. Breadcrumb. csproj.

Use Visual Studio to open the solution (ZKEASOFT. CMS. Web) and add an existing project under the Modues directory:

Find Easy. CMS. Breadcrumb. csproj and add:

Modify namespace component name and other related information

Open the properties of Easy. CMS. Breadcrumb and modify the Assembly name and namespace to: Easy. CMS. Breadcrumb.

Change the StandardPlug class name to BreadcrumbPlug and delete the registered routing code, because the navigation component to be added does not need

Method description:

RegistRoute () is used to register the ingress of a component.

AdminMenu () is used to add the left-tested menu at the backend.

The InitScript () method is used to integrate the registration script for ease of use in the View.

The InitStyle () method is used to integrate the registration style for easy use in the View.

Next, open the CopyItems. xml file and modify the content:

The purpose of this file is to copy the DLL to the bin directory of the web to facilitate debugging, or you can directly generate a directory to the bin directory of the web.

Next we will start Coding.

Under the Models directory, add a BreadcrumbWidget class and add the following code:

namespace Easy.CMS.Breadcrumb.Models{    [DataConfigure(typeof(BreadcrumbWidgetMetaData))]    public class BreadcrumbWidget : WidgetBase    {        public bool IsLinkAble { get; set; }    }    class BreadcrumbWidgetMetaData : WidgetMetaData<BreadcrumbWidget>    {        protected override void ViewConfigure()        {            base.ViewConfigure();            ViewConfig(m => m.IsLinkAble).AsHidden();        }    }}

BreadcrumbWidget inherits from WidgetBase and has its own attribute IsLinkAble. Since IsLinkAble is useless now, it is hidden.

The Entity BreadcrumbWidget corresponds to a table named BreadcrumbWidget by default. The fields required for this table are ID and IsLinkAble.

Add a BreadcrumbWidgetService class under the Service directory and add the following code:

namespace Easy.CMS.Breadcrumb.Service{    public class BreadcrumbWidgetService : WidgetService<BreadcrumbWidget>    {        private IPageService _pageService;        public IPageService PageService        {            get { return _pageService ?? (_pageService = ServiceLocator.Current.GetInstance<IPageService>()); }        }        private List<PageEntity> _parentPages;        public List<PageEntity> ParentPages        {            get { return _parentPages ?? (_parentPages = new List<PageEntity>()); }        }        public override WidgetPart Display(WidgetBase widget, HttpContextBase httpContext)        {            GetParentPage(httpContext.GetLayout().Page);            return widget.ToWidgetPart(ParentPages);        }        void GetParentPage(PageEntity page)        {            ParentPages.Insert(0, page);            if (page.ParentId.IsNotNullAndWhiteSpace() && page.ParentId != "#")            {                var parentPage = PageService.Get(m => m.ID == page.ParentId).FirstOrDefault();                if (parentPage != null)                {                    GetParentPage(parentPage);                    }            }        }    }}

The code is relatively simple. The purpose is to retrieve all the parent pages of the current page and display these pages. Therefore, we need to add a View for display.

Add a view named Widget. Breadcrumb under the Views directory:

@model List<Easy.Web.CMS.Page.PageEntity><ol class="breadcrumb">    @for (int i = 0; i < Model.Count; i++)    {        if (i == Model.Count - 1)        {            <li class="active">@Model[i].PageName</li>        }        else        {            <li><a href="@Url.Content(Model[i].Url)">@Model[i].PageName</a></li>        }    }</ol>
Integration with the System

Add a Content directory and add a 256x256 image to it as the thumbnail of the component. The thumbnail will be displayed when you select the component.

Create a BreadcrumbWidget table

CREATE TABLE BreadcrumbWidget    (      ID NVARCHAR(100) PRIMARY KEY                       NOT NULL ,      IsLinkAble BIT NULL    );

Add a record to the CMS_WidgetTemplate table to notify the system of a new component:

Insert into dbo. CMS_WidgetTemplate (Title, GroupName, PartialView, AssemblyName, ServiceTypeName, ViewModelTypeName, Thumbnail, [Order], Status) VALUES (n' path navigation ', n' 1. generic ', n' widgets. breadcrumb', n' Easy. CMS. breadcrumb', n' Easy. CMS. breadcrumb. service. breadcrumbWidgetService ', n' Easy. CMS. breadcrumb. models. breadcrumbWidget ', n '~ /Modules/Breadcrumb/Content/breadcrumb.png ', 6, 1)

Run the program:

How to display component fields in English? Go directly to the Language table to Update them. How can we find them?

SELECT * FROM dbo.Language WHERE Module=N'BreadcrumbWidget'

Or, use the following script to initialize multilingual text before running the program.

INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (N 'breadcrumbwidget @ actiontype', 2052, N 'actiontype ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ assemblyname', 2052, n' assemblyname ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ createby', 2052, n' createby ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ createbyname', 2052, n' creator ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ createdate', 2052, n' creation date', n' BreadcrumbWidget ', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (N 'breadcrumbwidget @ mmclass', 2052, N 'customclass ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (N 'breadcrumbwidget @ mmstyle', 2052, N 'customstyle ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ description', 2052, n' description ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ formview', 2052, n'formview ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ id', 2052, n' id ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ IsLinkAble ', 2052, n' IsLinkAble ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ issystem', 2052, n' issystem ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ IsTemplate ', 2052, n' Save As template', n' BreadcrumbWidget ', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ lastupdateby', 2052, n' lastupdateby ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ lastupdatebyname', 2052, n' updater', n' BreadcrumbWidget ', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ lastupdatedate', 2052, n' update date', n' BreadcrumbWidget ', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ layoutid', 2052, n' la ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ pageid', 2052, n' page ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n'breadcrumbwidget @ partialview', 2052, n' templates ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (N 'breadcrumbwidget @ position', 2052, n ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ servicetypename', 2052, n' servicetypename ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ status', 2052, n' status ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ styleclass', 2052, N 'custom style', n'breadcrumbwidget ', n'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ Thumbnail ', 2052, n' template thumbnails ', n' BreadcrumbWidget', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ title', 2052, n' title ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ viewmodeltypename', 2052, n' viewmodeltypename ', N 'breadcrumbcomponents', N 'entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ widgetname', 2052, n' component name', n' BreadcrumbWidget ', n' entityproperties') INSERT [dbo]. [Language] ([LanKey], [LanID], [LanValue], [Module], [LanType]) VALUES (n' BreadcrumbWidget @ zoneid', 2052, n' region ', N 'breadcrumbcomponents', N 'entityproperties ')

 

Do you have any questions? Join us to answer your questions

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.