[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:
<?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.' ',
'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();
?>
HTML Output
Code:
<form action="http://domain.com/login" method="post">
<div id="content">
<div id="msg">Enter your Username & Password to continue </div>
<div id="login">
<div class="labels">
<div class="tr">Username: </div>
<div class="tr">Password: </div>
</div>
<div class="inputs">
<div class="tr"><input type="text" name="username" value="admin" maxlength="500" size="50" class="bx" /></div>
<div class="tr"><input type="password" name="password" value="" maxlength="500" size="50" class="bx" /></div>
</div>
<input type="submit" name="btn" value=" login " id="btn" />
</div>
</div>
</form>