简体   繁体   中英

Hippo CMS tutorial and MVC

I'm new to Hippo CMS and went through the tutorial. Everything went smoothly. But, I have a couple of questions and was hoping to get answers.

1) Do I need to create a new controller for every document I create? Or Can I simply repeat the following line of code for every document in one controller:

Simpledocument document = (Simpledocument) ctx.getContentBean();

    if (document != null) {
        // Put the document on the request
        request.setAttribute("document", document);
    }

It just doesn't make total sense to me that I should have to create a new controller for every single document. This could get messy.

2) The steps done to create the dynamic hello world document in Hippo CMS Console. Do I have to follow all those steps for every document? I have a feeling I do..

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);
        }
    }
}

Of course, HelloWorldTut and HelloWorldList are two different document types.

every component needs a controller, and a page can have multiple components. But of course you can reuse code and components. A page is rendered based on which sitemap item is matched from the url. This is attached to a page configuration which defines the components (or containers for components used in the channel manager). You don't even need a sitemapitem per document. Using wildcards you can match urls based on patterns.

2) For every document type. If you have to configure for each document it would quickly become unmanageable. If you have documents all of one type, you can match to the same page configuration each time. By using wildcards in the sitemapitem and assuming that the url matches on the name of the document you can match every document.

I had a similar question that was answered today at https://community.bloomreach.com/t/controller-for-every-view/744/3

You don't have to have a controller if you don't need custom processing. You can use the <#assign document=hstRequestContext.contentBean /> in you view template to get the content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM