创建用于果园,从前端存储数据的模块 [英] Creating a module for Orchard that stores data from the front-end

查看:252
本文介绍了创建用于果园,从前端存储数据的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code将在以后只要我在我的开发机器名列前茅,但希望在此期间,有人能帮助....

Code will come later as soon as i am in front of my development machine, though hoping in the meantime someone can help....

我想在果园CMS V1.6.1发展。目前,我公司在试图开发一个模块,将从根本上让我把页脚中的新闻订阅视图(或其他任何地方我选择)在前端的万幸。

I am trying to develop on Orchard CMS v1.6.1. At the moment I am in the midst of trying to develop a module that will essentially allow me to place a Newsletter subscription view within the footer (or anywhere else i choose) on the front end.

我按照一些教程和他们似乎都说明如何将数据从只管理存储 - 我需要存储在前端数据以及管理......这就是我正在寻找的帮助。 ..

I have followed several tutorials and they all seem to show how to store data from the Admin only - I need to store data on the FRONT end as well as the admin... This is what I am looking for help on...

所以,到目前为止,我的模块有所有正常驱动器/处理器/ editorTemplates视图/迁移/ contentpart / contentpartrecord,我可以创建在管理一个订阅条目 - 我有我的内容类型的设置,看看我的模块中管理员。

So, so far, my module has all the "usual" driver/handler/editorTemplates view/migrations/contentpart/contentpartrecord and i can create a subscription entry in the admin - I have my content Type setup and see my module in the admin.

选择您喜欢的模块的任何教程,这就是我走的道路 - 它们似乎都相同创建一个模块并通过管理存储数据方面....

Pick any tutorial on modules you like and that's the path i followed - they all seem to be the same in terms of creating a module and storing data via the admin....

与其他问题的答案我设法模块显示在前端 - 这是在我的司机覆盖显示和使用shapeHelper.DisplayTemplate()方法的方法。

With answers from other questions I managed to get the module to display on the front-end - this is by way of overriding Display in my driver and using the shapeHelper.DisplayTemplate() method.

虽然一些奇怪的事情 - 在前端(与我的窗体现在显示拜Placement.info)第一次加载页面我得到了我的数据库表中的空白项(订阅表) - 这种情况实际上不回发。我没有什么不知道什么code的一部分,是导致这种情况发生。这需要不会发生 - 我只希望当用户填写表单,并点击提交存储数据

Some strange things though - when the front-end (with my form now displayed thanks to Placement.info) page first loads I get a blank entry in my database table (subscriptions table) - this happens without actually posting back. I have little to no idea what part of code is causing this to happen. This needs to not happen - i only want to store data when the user fills out the form and clicks submit.

其次,我需要在实际存储数据稍加引导用户进入在前端..

Secondly, I need a little guidance in actually storing the data the user enters in on the front end..

通常情况下我应该有我的模块存储在前端输入的数据吗?

Typically what should I have in my module to store data entered in the front end?

我不实际的code之后 - 正好与我应该做的想法。我在Web表单开发典型,因此MVC是一个小新给我。

I'm not after actual code - just an idea of what i should be doing. I develop in web forms typically, so MVC is a little new to me.

我应该有一个控制器/路由等?

should i have a controller/route etc?

我应该在前端显示的形式从我所创建的模块有所不同的?

should the form i display on the front-end be somewhat separate from the module i have created?

有人能指出我在你做什么来存储数据果园内的正确方向?

Can someone point me in the right direction of what you do to store data inside of Orchard?

我想在这一点上任何帮助将是巨大的......

I guess at this point any help would be great...

更新

感谢您到目前为止给出的答案。在这种情况下,我可以使用自定义表单,但不想。我最好要保存在它自己的表中的数据。

Thank you for the answers given so far. In this case I could use custom forms, though don't want to. I ideally want the data stored in it's own table.

此外,该模块会给我的基础,我需要创建更复杂的模块将从前端存储数据。我刚才似乎无法让我的头周围果园如何拆线这一切在一起..即通过控制器将数据存储到果园system..what code,我会需要我的表中创建一个新的行?

Also, this module will give me the basis i need to create more complex modules that will store data from the front-end. I just can't seem to get my head around how Orchard stitches this all together.. I.E storing data via the controller into the orchard system..what code would i need to create a new row in my table?

推荐答案

好了,你正在做在管理什么是创建内容类型。我不知道你真的需要被存储以这样的方式订阅。但是,也许我不明白您的情况,所以如果这是你希望继续,你可能想看看果园自定义窗体。我承认,这是最初不清楚如何从前端创建内容类型。你可以看一下本教程介绍如何使用果园自定义窗体。 <一href=\"http://devdirective.com/post/160/how-to-create-custom-forms-in-orchard-cms-with-email-and-recaptcha\">http://devdirective.com/post/160/how-to-create-custom-forms-in-orchard-cms-with-email-and-recaptcha他们正在创造有这个例子是一个接触的形式。这是pretty简单居然和非常强大的。我相信它被包含在核心。对于1.7最少。

Well, what you are doing in the admin is creating a content type. I'm not sure you really need to be storing subscription in such a way. But maybe I don't understand your scenario so if this is how you wish to proceed, you may want to check out Orchard Custom Forms. I admit, it is initially unclear how to create content types from the front end. You can look at this tutorial on how to use Orchard Custom Forms. http://devdirective.com/post/160/how-to-create-custom-forms-in-orchard-cms-with-email-and-recaptcha The example they are creating there is a contact form. It is pretty simple actually, and very powerful. I believe it is included in the core. For 1.7 at least.

但是,对于一个新闻订阅你的情况,我会说你可能需要一个不同的方法,并简单地存储订阅你的通讯在他们自己的表的电子邮件列表。

However, for your situation with a newsletter subscription I would say you may want a different approach, and simply store a list of emails that are subscribed to your newsletter in their own table.

有关这一点,你需要创建自己的控件,与显示一个表单链接到提交他们的电子邮件自己的自定义控制器部分,然后将其保存。这将全部采用简单的MVC做,你会想看看教程上。

For this you will need to create your own widget, with a part that displays a form linking to your own custom controller that submits their email and then saves it. This would all be done using simple MVC and you would want to check out tutorials on that.

如果您的用户在登录即可订阅您的通讯中,您可能更聪明,重视用户的一部分,该更新时,他们说,他们想订阅电子报。但现在我胡侃。

If your users have to be logged in to subscribe to your newsletter you could be even more clever and attach a part to the user and update this when they say they want to subscribe to your newsletter. But now I am babbling.

我已经那种刚刚扔在如何去创建自己的小工具来显示表单很模糊的想法。我很乐意提供一些更详细的,如果你觉得这是你可能要往下走的路线。否则......我懒得^ _ ^

I have sort of just thrown very vague ideas on how to go about creating your own widget to display a form. I'd be happy to provide some more detail if you think this is a route you may want to go down. Else...I'm too lazy ^_^

更新:

好吧,我看到尼克给你如何去这一些指点。我开始阅读,但觉得无聊,觉得这听起来pretty多少罚款,但。以为我只是添加我的两个便士的价值。我在果园不是专家,但,这是这一切是如何在我看来。更正我的废话太多AP preciated。

Okay, so I see Nick has given you some pointers on how to go about this. I started reading but got bored, think it sounds pretty much fine though. Thought I'd just add my two pennies worth. I'm no expert in Orchard but this is how it all seems to me. Corrections to my nonsense much appreciated.

部分缝合到内容类型。一部分是由几个部分......你明白我的意思。

Parts are stitched onto Content Types. A part consists over several parts... You see what I mean.


  • 司机:这基本上是一个控制器。它显示视图人们会看到在前端,当你创建的内容项将要显示的编辑器。它还处理时创建的内容项目回传,验证等。

  • 的模式:这是在那里你会存储有关部分的数据。所以,如果你有相关的部分的任何设置。此继承的东西,赋予其它连接到所述内容项目的ID。不能记住的名字。

  • 的处理程序:这基本上是处理创造你的内容项目。它会另送您的数据到存储库,并可以做其他的东西巧妙。您可以删除自定义逻辑到其提供的服务。但是不要担心,只要把它做它的东西。

  • 的意见:内容部分有与之相关的几个观点。编辑视图和显示视图。这些都存储在单独的文件夹。 EditorTemplates /配件/ ...是你的编辑器将存储(当你创建的内容项中所示)。配件/ ...是存储你的意见,显示前端的东西。

  • 放置:此文件包含有关您的部分将内容项中显示的信息。这是pretty凉爽。

因此​​,我们需要的第一件事情就是创建零件本身。你可以把它写自己所有。但它是繁琐和容易当你是新来忘记的事。我总是忘记一些重要的事情。有VS可从模板某处。我通常只用一个很酷的小code生成模块。所以去画廊,通过Piotr szmyd下载并启用code代扩展。现在,您可以运行命令行应用程序Orchard.exe。它被保存在内部Orchard.Web bin文件夹。检查此博客张贴有关如何使用此模块的详细信息。 <一href=\"http://www.szmyd.com.pl/blog/generating-orchard-content-parts-via-command-line\">http://www.szmyd.com.pl/blog/generating-orchard-content-parts-via-command-line

So the first thing we need is to create the part itself. You can write it all yourself. But it is tedious and easy to forget something when you are new. I always forget something important. There are vs templates available from... somewhere. I usually just use a cool little code generation module. So go to the gallery and download and enable Code Generation Extensions by piotr szmyd. You can now run the command line application Orchard.exe. This is stored in the bin folder within Orchard.Web. Check this blog post for details on how to use this module. http://www.szmyd.com.pl/blog/generating-orchard-content-parts-via-command-line

右键,所以我们将创建一个使用此命令调用NewsletterPart一部分。

Right so we will create a part called NewsletterPart using this command.

codeGEN部分YourModuleName NewsletterPart

codegen part YourModuleName NewsletterPart

这将产生所有必要位和乙,驱动等你的部分应该并不真正需要的任何设置。也许在未来,当它需要简单,所以现在我们将离开模型空白。我们将把您的通讯的订户名单存放在不同的表。在一个位。首先让我们得到它,以显示你的一部分。应该有你的浏览/配件/文件夹中的文件NewsletterPart.cshtml。写一些随机单词在这里,所以我们知道它正在显示。然后去Placement.info文件,并确保它在有一条线,告诉你的一部分来显示。例如:

This will generate all the necessary bits and bobs, drivers etc. Your part shouldn't really need any settings. Maybe in the future when it needs to be simple so for now we will leave the models blank. We will store your list of newsletter subscribers in a different table. In a bit. First lets get it to display your part. There should be a NewsletterPart.cshtml file in your Views/Parts/ folder. Write some random words in here so we know it is displaying. Then go to the Placement.info file and make sure it has a line in there that tells your part to be displayed. eg:

&LT;将Parts_NewsletterPart =内容:5/>

< Place Parts_NewsletterPart="Content:5" />

现在我们确实需要创建你的一部分,让您可以显示在你的部分部件。这是通过迁移文件中完成的。

Now we actually need to create your part and make a widget that you can display your part in. This is done with the migrations file.

    using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Orchard.Environment.Extensions;

namespace MyModule {
    public class Migrations : DataMigrationImpl {

        public Migrations() {

        }

        public int Create() {
        // Create Newsletter part table
            SchemaBuilder.CreateTable("NewsletterPartRecord", table => table
                .ContentPartRecord()
            );

        // Create the part and make it attachable to content items
            ContentDefinitionManager.AlterPartDefinition("NewsletterPart", builder => builder.Attachable());

        return 1;
    }

    public int UpdateFrom1() {
        // Create Widget
        ContentDefinitionManager.AlterTypeDefinition("NewsletterWidget", cfg => cfg
                .WithPart("NewsletterPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));

            return 2;   
    }
    }

    }

您现在应该能够创建仪表盘上的小工具,它会出现在页脚。

You should now be able to create a widget on the dashboard and it will appear in footer.

现在,我们需要创建一个小的形式来显示一些东西。表单将是这个样子。查入部分显示视图,而不是不管你写的了。

Now we need to create a little form to display some stuff. The form will look something like this. Chuck it into the parts display view instead of whatever you wrote before.

@model dynamic

@using (Html.BeginForm("Subscribe", "Subscription", FormMethod.Post))
{
    <fieldset>
        @Html.AntiForgeryTokenOrchard()    

        <label >
            Email:</label>
        @Html.TextBox("Email")<br />


        <button class="primaryAction" type="submit">@T("Submit")</button>
    </fieldset>
}

现在可以让模型对这种形式的工作。创建模型文件夹中的文件调用类似以下内容订阅模式:

Now lets make the model for this form to work. Create a file in the models folder called Subscription Model with something like the following:

using System;

namespace MyModule.Models
{
    public class SubscriptionModel
    {
        public SubscriptionModel() 
        {

        }

        public virtual int Id { get; set; }

        public virtual string Email { get; set; }


    }
}

这将存储您的电子邮件订阅。现在,你需要做的其实这种事情。我们可以创建将处理所有的控制器。创建一个文件夹名为控制器,然后添加一个名为SubscriptionController.cs。添加一个名为订阅,可以看起来像这样的方法:

This will store your email subscribers. Now you need to actually do something with this. We can create the controller that will handle everything. Create a folder called Controllers and then add a file called SubscriptionController.cs. Add a method called Subscribe that can look something like this:

public class SubscriptionController : Controller {

   private readonly IRepository<EmailModel> emailRepository;

   public SubscriptionController(IRepository<EmailModel> emailRepository) {


    this.emailRepository = emailRepository;

        [HttpPost]
        public ActionResult Subscribe(string email)
        {
            var record = new EmailRecord() {
        Email = email
        };

        this.emailRepository.Create(record);


            //return to return url
        }
   }
}

所有剩下要做的就是在数据库中创建emailrecord表。返回迁移和添加新方法。

All that is left to do is to create your emailrecord table in the db. Back to migrations and add a new method.

public int UpdateFrom2() {
   SchemaBuilder.CreateTable("EmailModel", table => table
                .Column<string>("Email")
                .Column<int>("Id", column => column.PrimaryKey()));

   return 3;
}

只是样品我在记事本写了那么可能不会编译。得到多一点的时间比我预计的......我的blunderings。

Just samples I wrote in notepad so probably will not compile. Got a bit longer than I expected...my blunderings.

这篇关于创建用于果园,从前端存储数据的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆