italiano
  • english
  •  
     
     
    BEdita | Semantic Content Management Framework

    Customizing Frontend Applications [part 2]: how to load only selected content in a section

    Improve speed performance by narrowing your requests to the API

    published on 11-27-2009  by Alberto Pagliarini
    tag:  frontendcustomizecontentsperformance

    While programming, you can request the content of a certain section by URL, with something like http://www.example.com/section-nickname/content-nickname. The requested content is loaded into the $section["currentContent"] array, while more content – actually every content in the same section – is placed into the $section["childContents"] array. This additional content is loaded in "base level mode" (cfr. the API manual, "baseLevel"), which means that only basic informations about various objects are given (such as the title, the description, its ID and a few more).

    Now this is indeed useful in standard scenarios: when you are showing a particular content and listing, at the same time, related contents in the same section. Imagine you are showing an article and you want to put links to more contents in a contextual menu. This is common, but sometimes you are interested only in a single object, while you don't really need to load all related stuff.

    In these cases you can improve the data loading performance by excluding this additional content (you actually give up the option of having also $section["childContents"] array). Obviously the improvement will be much more evident when that particular section is burdened, it has got many objects inside.

    However, moving forward into the discussion started in the previous article "Customizing Frontend Applications [part 1]: divide objects by type in a section", we're going to use the Frontend Controller attribute $sectionOptions. This time too, we may proceed in two different ways, the choice depending on whether we want a custom behavior for a specific section (1) or alternatively we prefer to modify the default behavior for the whole frontend application (2).

    So I'm showing you both:

    1. Custom behavior for a section 

    Like we did in the previous post, we are going to use the nicknameBeforeFilter callback: It is automatically called before section data are loaded, so in the controller:

    protected function section-nicknameBeforeFilter() {
         $this->sectionOptions["showAllContents"] = false;
    }

    (pay attention to change "section-nickname" with the exact nickname of your section).

     

    2. Change the default behavior

    To change the way the API answers to requests, edit your Pages Controller. You have to change the $sectionOptions attribute, by setting the showAllContents property to false:

    protected $sectionOptions = array("showAllContents" => false, "itemsByType" => false, "childrenParams" => array());

    When showAllContents is set to false, we say to the API to not load all related content when a specific content is requested.

    2  Comments

    Gabriele

    12-11-2009

    Salve,
    E' davvero molto interessante il vostro progetto/prodotto e mi piacerebbe essere informato sulle novità. Non mi pare di aver trovato sul sito un link rss del blog, esiste?
    Grazie

    Stefano Rosanelli

    12-11-2009

    Gabriele,
    grazie dell'interessamento.
    Non abbiamo messo un link esplicito/bottone [lo faremo]
    Il feed rss dovrebbe "suggerirtelo" il tuo browser, in ogni caso sul sito ne trovi pubblicati due (blog & news):
    - http://www.bedita.com/rss/blog
    - http://www.bedita.com/rss/news

    [ogni sezione in BEdita e' pubblicabile automaticamente come feed RSS]

    Write a comment