Orchard(四):创建Module --Hello World

来源:互联网 发布:淘宝网店没人 编辑:程序博客网 时间:2024/05/16 15:48

之前系列文章

Orchard(一):介绍

Orchard (二):简单配置

Orchard(三):搞清来龙去脉(1)-初探

Orchard(三):搞清来龙去脉(2)-Widgets

Orchard(三):搞清来龙去脉(3)-Orchard 是怎么运行的?

复习些概念

  Orhcard的上层是基于微软MVC搭建的。Module最被解析为Area来使用的。(Area可以简单的视为一个子系统模块,类似为虚拟目录所代表的含义)

准备工作

  安装使用Code.Generation,具体可以看教程《Orchard(四):Orchard中的Scanffolding(Command line scaffolding)-工具说明

步骤:

1.打开Orchard命令行工具(在你的站点下面的bin或者debug中有一个orchard.exe文件),输入命令(创建HelloWorld Module)

   

codegen module HelloWorld

  

此时会通知重载项目,并已经新增HelloWorld Module

2.修改Manifest文件,主要是开启该Module,告诉调用者一些基本信息。

Name: HelloWorldAntiForgery: enabledAuthor: WTWebsite: http://orchardproject.netVersion: 1.0OrchardVersion: 1.0Description: Description for the moduleFeatures:    HelloWorld:        Description: Sample,just for study.Category: Sample

注意:不允许tabs,只允许空格在这个文本文档中。

3.创建路由.

/*-------------------------------------------------------------------------* 版权所有:吻天开发团队* 作者:邓福勇* 联系:dfyong@hotmail.com* 操作:创建* 时间:12/26/2011 9:48:47 AM * CLR版本:4.0.30319.239* 唯一标识:c2fae6f7-fda5-4c23-b2fc-470867550597* 版本号:v1.0* 功能说明:*  -------------------------------------------------------------------------*/using System.Collections.Generic;using System.Web.Mvc;using System.Web.Routing;using Orchard.Mvc.Routes;namespace HelloWorld{    public class HelloWorldRouts : IRouteProvider    {        public void GetRoutes(ICollection<RouteDescriptor> routes)        {            foreach (var routeDescriptor in GetRoutes())                routes.Add(routeDescriptor);        }        public IEnumerable<RouteDescriptor> GetRoutes()        {            return new[] {                new RouteDescriptor {                    Priority = 5,                    Route = new Route(                        "HelloWorld",                        new RouteValueDictionary {                            {"area", "HelloWorld"},                            {"controller", "Home"},                            {"action", "Index"}                        },                        new RouteValueDictionary(),                        new RouteValueDictionary {                            {"area", "HelloWorld"}                        },                        new MvcRouteHandler())                }            };        }    }}


4.创建Controller

/*-------------------------------------------------------------------------* 版权所有:吻天开发团队* 作者:邓福勇* 联系:dfyong@hotmail.com* 操作:创建* 时间:12/26/2011 9:52:40 AM * CLR版本:4.0.30319.239* 唯一标识:aa52d1a7-05bf-4d0c-bcd3-af62dfed15b1* 版本号:v1.0* 功能说明:*  -------------------------------------------------------------------------*/using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.Mvc;using Orchard.Themes;namespace HelloWorld.Controllers{    public class HomeController:Controller    {        [Themed]        public class HomeController : Controller        {            public ActionResult Index()            {                return View("HelloWorld");            }        }    }}


5. 创建View

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.Mvc;using Orchard.Themes;namespace HelloWorld.Controllers{    [Themed]    public class HomeController : Controller    {        public ActionResult Index()        {            return View("HelloWorld");        }    }}


6. 生成解决方案。

7. 成功后,启动HelloWorld Module(当然,也可以到后台管理页面去启动)


/*-------------------------------------------------------------------------* 版权所有:吻天开发团队* 作者:邓福勇* 联系:dfyong@hotmail.com* 操作:创建* 时间:12/26/2011 9:52:40 AM * CLR版本:4.0.30319.239* 唯一标识:aa52d1a7-05bf-4d0c-bcd3-af62dfed15b1* 版本号:v1.0* 功能说明:*  -------------------------------------------------------------------------*/using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.Mvc;using Orchard.Themes;namespace HelloWorld.Controllers{    public class HomeController:Controller    {        [Themed]        public class HomeController : Controller        {            public ActionResult Index()            {                return View();            }        }    }}

看效果: