Welcome Guest, Not a member yet? Register   Sign In
div structure helper
#1

[eluser]wiredesignz[/eluser]
application/helpers/div_structure_helper.php
Code:
function div_construct($attributes = NULL, $structure = array(), $tab = 0, $crlf = "\n")
{
    $tabs = str_repeat("\t", $tab);
    $crlf .= $tabs;
    
    foreach ($structure as $key => $content)
    {
        $id  = (!is_numeric($key)) ? ' id="'.$key.'"' : '';
        $cls = ($attributes[$key]) ? ' class="'.$attributes[$key].'"' : '';
        
        echo ($attributes) ? $crlf.'<div'.$id.$cls.'>' : $crlf;
        echo (is_array($content)) ? div_construct(&$attributes, $content, $tab+1).$crlf : $content;
        echo ($attributes) ? '</div>' : '';
    }
}

sample login form using div_structure_helper
application/views/login.php
Code:
&lt;?php
    echo form_open($action);
    div_construct(
        //css class attributes
        array(
            3 => 'labels',
            4 => 'tr',
            5 => 'tr',
            6 => 'inputs',
            7 => 'tr',
            8 => 'tr',
            9 => '',
        ),
        //css id attributes + structure
        array(
            'content' => array(
                'msg' => $message.' &nbsp;',
                'login' => array(
                    3 => array(
                        4 => 'Username: ',
                        5 => 'Password: ',
                    ),
                    6 => array(
                        7 => form_input('username', $username, 'class="bx"'),
                        8 => form_password('password', $password, 'class="bx"'),
                    ),
                9 => form_submit('btn',' login ', 'id="btn"'),
                )
            )
        )
    );
    echo form_close();
?&gt;

HTML Output
Code:
&lt;form action="http://domain.com/login" method="post"&gt;
<div id="content">
    <div id="msg">Enter your Username &amp; Password to continue &nbsp;</div>
    <div id="login">
        <div class="labels">
            <div class="tr">Username: </div>
            <div class="tr">Password: </div>
        </div>
        <div class="inputs">
            <div class="tr">&lt;input type="text" name="username" value="admin" maxlength="500" size="50" class="bx" /&gt;</div>
            <div class="tr">&lt;input type="password" name="password" value="" maxlength="500" size="50" class="bx" /&gt;</div>
        </div>
        &lt;input type="submit" name="btn" value=" login " id="btn" /&gt;
    </div>
</div>
&lt;/form&gt;


Messages In This Thread
div structure helper - by El Forum - 01-30-2008, 08:56 PM
div structure helper - by El Forum - 01-31-2008, 01:12 AM
div structure helper - by El Forum - 01-31-2008, 01:38 AM
div structure helper - by El Forum - 01-31-2008, 01:47 AM
div structure helper - by El Forum - 01-31-2008, 02:28 AM
div structure helper - by El Forum - 01-31-2008, 02:43 AM
div structure helper - by El Forum - 01-31-2008, 04:52 AM
div structure helper - by El Forum - 01-31-2008, 05:02 AM
div structure helper - by El Forum - 01-31-2008, 05:10 AM
div structure helper - by El Forum - 01-31-2008, 05:31 AM
div structure helper - by El Forum - 01-31-2008, 05:33 AM
div structure helper - by El Forum - 01-31-2008, 05:38 AM
div structure helper - by El Forum - 01-31-2008, 06:21 AM
div structure helper - by El Forum - 01-31-2008, 08:47 AM
div structure helper - by El Forum - 01-31-2008, 09:10 AM
div structure helper - by El Forum - 01-31-2008, 09:46 AM
div structure helper - by El Forum - 01-31-2008, 10:23 AM
div structure helper - by El Forum - 01-31-2008, 10:34 AM
div structure helper - by El Forum - 02-01-2008, 04:49 PM
div structure helper - by El Forum - 02-01-2008, 08:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB