Correct definition form class
i have class
class Form {
public开发者_如何转开发 function addTextarea(array $par){
$element='. $par['label'] .';
$element .= '<textarea name="'. $par['name'] .'" id="'. $par['id'] .'" cols="'. $par['cols'] .'" rows="'. $par['rows'] .'" class="' $par['class'] '"></textarea>' ;
return $element;
}
// another form elements
}
$tab1 = array (
'name'=>'newsletter',
'id'=>'nwsltr',
'cols'=>'10',
'rows'=>'5',
'class'=>'newsletter',
'label'=>'Subscribe',
'value'=> $_POST['email']
);
$ob->new Form;
print $ob->addTextarea($tab1);
Did this pattern is good ? How i can simple write array, another write class ?
This one is better
<?php
class Form {
public function addTextarea(array $par){
$element = $par['label'];
$element .= '<textarea name="'. $par['name'] .'" id="'. $par['id'] .'" cols="'. $par['cols'] .'" rows="'. $par['rows'] .'" class="'. $par['class']. '"></textarea>';
return $element;
}
}
$tab1 = array (
'name'=>'newsletter',
'id'=>'nwsltr',
'cols'=>'10',
'rows'=>'5',
'class'=>'newsletter',
'label'=>'Subscribe',
'value'=> $_POST['email']
);
$ob = new Form;
print $ob->addTextarea($tab1);
http://sandbox.phpcode.eu/g/fcd58.php
精彩评论