Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Widgets advice
  • So having most of my base coding done, im wondering how best to handle widgets like addictions to the pages. For example users online or recent posts. if i want it to appear when i add a function like this to the views:
    <div class="wid">
             <?php recent_posts() ?>
    </div>
    

    How would i go about doing it? would i use ViewModels? Or make a separate class Widgets in the classes folder ?
    <div class="wid">
             <?php Widgets::recent_posts() ?>
    </div>
    

    Thanks for any advice.
  • Harro Verton wrote on Saturday 11th of June 2011:
    My widgets are all produced by module controllers, which I call through a Request object. This allows you to code your widgets completely independent of your application code, making them very reusable.
    <div class="wid">
        <?php echo \Request::factory('module/controller/method/parm1/parm2', false)->execute()->response(); ?>
    </div>
    
    I've got this information in the database, for every page and every section on the page, which widgets to load. I have a single controller processing the theme template, fetching the widgets, and rendering the page. Nothing hardcoded in the templates.

    Thanks for the advice, ill give modules another try.
  • My widgets are all produced by module controllers, which I call through a Request object. This allows you to code your widgets completely independent of your application code, making them very reusable.
    <div class="wid">
        <?php echo \Request::factory('module/controller/method/parm1/parm2', false)->execute()->response(); ?>
    </div>
    
    I've got this information in the database, for every page and every section on the page, which widgets to load. I have a single controller processing the theme template, fetching the widgets, and rendering the page. Nothing hardcoded in the templates.
  • Hi Harro,

    can you show structure of your database (relations between widgets / pages and sections) and snippet of your theme controller who fetching widgets and rendering page.

    Thank you
  • Unfortunately, I can not, it is a core part of our application framework which my company uses to make money with.

    But the stucture is very logical. The pages table is a nested-set implementation (as webpages are organised in a tree structure). Every page has sections, every section can contain one or more widgets. Sections can enforce a specific type, for example only nested-set menu widgets in a navigation section.

    The controller does a lookup for the correct page using the uri segments, and then renders the page by fetching the page template, calling the widget controllers, and assign their output to the page template.

    The structure is not unlike Joomla's theming system, from which the architecture was borrowed.

    Obviously there is more involved than this (multiple themes, default widgets, etc).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion