Re: Datagrid Renderers: Supported operation modes

From: Date: Mon, 12 Jun 2006 16:27:57 +0000
Subject: Re: Datagrid Renderers: Supported operation modes
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24325@lists.php.net to get a copy of this message
Hi Michel, Michel D'HOOGE wrote:
Hello, In the comment of all renderers I saw, we have the same supported modes: * - Container Support: yes * - Output Buffering: yes * - Direct Rendering: no
You didn't saw them all. 5 out of 9 rendering drivers support a different set of operation modes than the ones above. These are : XML, XUL, CSV, Smarty and XLS.
If I have understood well, container support is related to fill(), output buff. to getOutput() and rendering to render(). However, the last 2 functions share most of their code, one returns the result of flatten while the other prints it. So I guess output buff. & rendering shall be both yes or no.
Container support is mainly related to fill() yes. However by reading the official drivers, there is something you can not understand. It might help you to read bug #5859, to understand how we came here. The idea, in addition to add/improve official drivers, is to encourage users to write their own drivers, and make this easy, for flexibility. And when they do, they should usually come up with the simplest form of driver : a "Direct rendering" renderer. Example : class MyRenderer extends Structures_DataGrid_Renderer {
    function init() { echo "<table>"; }
    function buildHeader($columns) {
        echo "<tr>";
        foreach ($columns as $col) echo "<th>{$col['label']}</th>";
        echo "</tr>";
    }
    function buildRow ($index, $data) {
        echo "<tr>";
        foreach ($data as $cell) echo "<td>$cell</td>";
        echo "</tr>";
    }
    function finalize() { echo "</table>"; }
} $myRenderer = new MyRenderer(); $datagrid->attachRenderer($myRenderer); $datagrid->render(); That sort of driver is very easy to write, and allows for maximum flexibility whenever using the HTMLTable-based driver appears to be limited/heavy. And you can do anything you like, HTML, RDF, C struct, whatever...
BTW, I can't understand the purpose of the else part of render():
    function render()
    {
        if ($this->_isOverloaded('flatten')) {
            $this->_isBuilt or $this->build();
            echo $this->flatten();
        } else {
            $this->build();
        }
    }
This, again, is one thing you can only understand if you think about "What sort of driver is the user going to write ? How easy can we make this process ?", not about the official drivers. render() checks if the the driver implements flatten(). If not, that's a "Direct rendering" driver. The good news is that the user does not need to care about flatten(). With the above routine, drivers are "by default" Direct rendering drivers. This way, the user only needs a few set of methods (as shown in the MyRenderer example above) to get something working. He can learn some more about flatten(), setContainer(), etc... if he needs to. But the the learning curve is smooth. Direct rendering drivers should usually be user-made, while official drivers may never support the "Direct rendering" operation mode, because it forbids the two other modes : "Container support" and "Output buffering". However, for high optimization we might end up with some official drivers that write directly to standard output. I hope it answers your question. In short : "Direct rendering" and "Output buffering" are different, and even opposite, modes. Regards, -- og

« previous php.pear.general (#24325) next »