我是Piranha CMS的新手(以及任何CMS中的新手)。我有一个关于将系统集成到现有MVC 5应用程序的问题。以下是我到目前为止所做的事情:
我遇到的问题是了解如何将现有页面带入管理器以及如何将它们公开给用户进行编辑。我确实查看了文档,但找不到任何专门用于此主题的内容。
非常感谢任何帮助。
谢谢。 丹尼尔D.
答案 0 :(得分:6)
从Piranha CMS获取数据到您现有的应用程序非常简单。
<强> 1。页面类型
首先,看一下您需要创建的不同页面类型(即您需要的不同类型的页面结构),并从管理器界面或代码创建它们。你会在这里找到文档:
<强> 2。创建页面
接下来,只需在管理器中创建所需的页面并添加内容即可。如果您想禁止用户添加页面,您可以随后删除“添加”按钮,方法是将CSS注入管理器或自定义它。
第3。将数据添加到模型
在这里,您有两种选择,要么让您的模型从PageModel继承,要么只是将带有CMS数据的新属性添加到现有模型中。
// With inheritance
public class MyModel : Piranha.Models.PageModel {
...
}
// With the CMS data in a property
public class MyModel {
public Piranha.Models.PageModel CMSData { get; set; }
}
<强> 4。获取数据
现在填充数据只是一个调用方法。您可以id
或permalink
访问它。让我们通过永久链接访问它,假设我们有一个包含固定链接about-us
的页面。只需将以下内容添加到您的控制器:
// With inheritance
public class MyController : Controller {
public ActionResult MyAction() {
// Get the CMS-data
var model = Piranha.Models.PageModel.GetByPermalink<MyModel>("about-us");
// Fill the model with your custom data
...
}
}
// With the CMS data in a property
public class MyController : Controller {
public ActionResult MyAction() {
// Create and fill your custom model
var model = new MyModel();
...
// Get the CMS-data
var model.CMSData = Piranha.Models.PageModel.GetByPermalink("about-us");
}
}
<强> 5。构造强>
请注意,如果您希望应用程序控制路由,则应将Piranha CMS配置为以被动模式运行。您可以在此处找到有关配置的文档:
我希望这有助于您开始使用!
此致
/哈坎