[英]Hippo CMS tutorial and MVC
我是Hippo CMS的新手,並完成了本教程。 一切順利。 但是,我有幾個問題,希望得到答案。
1)我需要為我創建的每個文檔創建一個新的控制器嗎? 或者我可以在一個控制器中為每個文檔重復以下代碼行:
Simpledocument document = (Simpledocument) ctx.getContentBean();
if (document != null) {
// Put the document on the request
request.setAttribute("document", document);
}
對我來說,完全沒有必要為每個文檔創建一個新的控制器。 這可能會變得混亂。
2)完成的在Hippo CMS Console中創建動態hello world文檔的步驟。 每個文檔都必須遵循所有這些步驟嗎? 我有一種感覺。
public class SimpleComponent extends BaseHstComponent {
public static final Logger log = LoggerFactory.getLogger(SimpleComponent.class);
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
// Retrieve the document based on the URL
HelloWorldTut document = (HelloWorldTut) ctx.getContentBean();
HelloWorldList docList = (HelloWorldList) ctx.getContentBean();
if (document != null) {
//Put the document on the request
request.setAttribute("doc", document);
request.setAttribute("docList", docList);
}
}
}
當然,HelloWorldTut和HelloWorldList是兩種不同的文檔類型。
每個組件都需要一個控制器,一個頁面可以包含多個組件。 但是,當然可以重用代碼和組件。 根據從網址中匹配的站點地圖項來呈現頁面。 這被附加到定義組件(或通道管理器中使用的組件的容器)的頁面配置中。 您甚至不需要每個文檔一個sitemapitem。 使用通配符,您可以根據模式匹配網址。
2)對於每種文檔類型。 如果必須為每個文檔進行配置,它將很快變得難以管理。 如果您擁有全部一種類型的文檔,則可以每次都匹配到相同的頁面配置。 通過在sitemapitem中使用通配符並假定url與文檔名稱匹配,您可以匹配每個文檔。
我今天在https://community.bloomreach.com/t/controller-for-every-view/744/3回答了類似的問題
如果不需要自定義處理,則無需控制器。 您可以在視圖模板中使用<#assign document=hstRequestContext.contentBean />
來獲取內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.