Access Keys:
Skip to content (Access Key - 0)
Home (Access Key - 1)
All spaces... (Access Key - 3)
Log in (Access Key - 5)
Sign up (Access Key - 6)
Development

Mambo Manual is part of the documentation project for the Mambo open source content management system

Toggle Sidebar

HTML Output Class Redefined


HTML Output Class 

Introduction

Not long ago, I got tired of passing certain common variables to every output function. So I decided to incorporate them into my output class instead. If you're familiar with the general layout of a typical output class, then what I'm about to present should make a lot of sense. I hope these examples will help you out along the way as you continue to contribute to the Mambo open source community.

The Old Way

Let's take a look at how the typical output class works. Normally, we call a function that collects the data we want displayed to the user. Then we call an HTML output class function to display the data.

The Logic

Here's a typical logic function. Notice how many variables are passed to the output function. In many cases, we always pass a few of the same variables to our output class. And each time we create a new output function, we have to remember to pass those same variables.

function myFunction( $id, $option, $task, $Itemid ) {
    global $my, $mosConfig_live_site;
    // do some processing
    $id = (int)$id;
    $name = $my->name;

    // output our data
    HTML_myOutput::show($id, $name, $option, $Itemid, $mosConfig_live_site);
}

The Output

Here's a typical output class. And there's those pesky common variables again. They're the same for just about every output function we write. And they're a pain to keep up with if we have multiple output functions.

class HTML_myOutput {
    function show( $id, $name, $option, $Itemid, $mosConfig_live_site ) {
?>
    <p>Hello, <?php echo $name<br />
    <p>The value for $id is <?php echo $id; ?></p>
    <p> </p>
    <p><a href="<?php echo "$mosConfig_live_site/index.php&option=$option&Itemid=$Itemid"; ?>">
    Return to My Component</a></p>
<?php
    }
}

A New Way

Have you ever spent time debugging your code only to discover you left out one of those common variables? Or maybe it was in the wrong order in the function parameter list and all kinds of strange things happened in your output.

Enter a new HTML output class. We'll be adding some new features that will help you keep those common variables straight.

Click the link below to continue your journey.
HTML Output Class Redefined - The New Way

Toggle Sidebar
Space Navigation
Added by Lynne Pope on 30 Dec, 2007 02:16, last edited by Lynne Pope on 03 Jan, 2008 10:48

Adaptavist Theme Builder Powered by Atlassian Confluence
Free theme builder license