Hi @all,
ich habe folgende Klassen jetzt mal zum test geschrieben um mir mal das mit extends näher zu bringen. Jetzt habe ich aber folgende Probleme:
- Return ist ein Object ==> warum?
- Ist der Code so richtig? Kommt mir alles ziehmlich verworren vor.
Klassen:
Ausgabe:
Kann man was verbessern oder muss man gar was ganz anders machen?
Thx @all
*edit code nochmal geändert
ich habe folgende Klassen jetzt mal zum test geschrieben um mir mal das mit extends näher zu bringen. Jetzt habe ich aber folgende Probleme:
- Return ist ein Object ==> warum?
- Ist der Code so richtig? Kommt mir alles ziehmlich verworren vor.
Klassen:
PHP:
<?php
/**
* Class 'html_form'
*
* @category HTML Form creator
* @autor Daniel Schumann <[email protected]>
* @version 1.0
* @copyright Copyright (c) 2007, Daniel Schumann
*/
define('SEPARATOR', "\n");
class html_form {
/**
* @var
*/
static $_out_object;
function __construct()
{
$this->_out_object = array();
}
function html_select($_name = NULL, $_value = NULL, $_label = NULL, $_size = 1, $_multiple = FALSE, $_selected = NULL) {
$_tmp = new select($_name, $_value, $_label, $_size, $_multiple, $_selected);
$this->_out_object[$_name] = @implode('', $_tmp->_string);
unset($_tmp);
}
function show()
{
echo @implode('', $this->_out_object);
$this->del;
}
function del()
{
unset($this);
}
}
class select extends html_form
{
var $_value;
var $_label;
var $_multiple;
var $_selected;
function __construct($_name = NULL, $_value = NULL, $_label = NULL, $_size = 1, $_multiple = FALSE, $_selected = NULL)
{
$this->_string = array();
/**
* NAME == NULL ==> Abbruch
*/
if($_name == NULL || $_value == NULL || $_label == NULL)
return;
$this->_value = is_array($_value) ? $_value : array($_value);
$this->_label = is_array($_label) ? $_label : array($_label);
$this->_multiple = (bool)$_multiple;
$this->_selected = is_array($_selected) ? $_selected : array($_selected);
/*
* selectfield anfangen mit bauen
*/
$_tmp = "<select name=\"".$_name."\" size=\"".$_size."\"";
if($this->_multiple)
$_tmp .= " multiple=\"multiple\"";
$_tmp .= ">";
$this->_string[] = $_tmp;
unset($_tmp);
// array von Value durchgehen und options bauen
for($_x = 0; $_x < count($_value); $_x++)
$this->add_option($_value[$_x], $_label[$_x], in_array($_x + 1, $this->_selected));
$this->_string[] = SEPARATOR . "</select>";
if(is_array($this->_string))
return $this->_string;
else
return SEPARATOR . "select error" . SEPARATOR;
}
function add_option($_value, $_label = NULL, $_selected = FALSE)
{
$res = SEPARATOR . " <option value=\"".$_value."\"";
if($_selected)
$res .= " selected=\"selected\"";
$res .= ">";
if($_label != NULL)
$res .= $_label;
else
$res .= $_value;
$res .= "</option>";
$this->_string[] = $res;
}
function __destruct()
{
unset($this);
}
}
$a = new html_form();
$a->html_select('test', array(1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9), array('hallo'
, 'hallo2'
, 'hallo3'
, 'hallo4'), 5, TRUE, 2);
$a->show();
?>
html_form Object
(
[_out_object] => Array
(
[0] => select Object
(
[_name] => test
[_value] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
)
[_label] => Array
(
[0] => hallo
[1] => hallo2
[2] => hallo3
[3] => hallo4
)
[_size] => 5
[_multiple] => 1
[_selected] => Array
(
[0] => 2
)
[_string] => Array
(
[0] =>
)
)
)
)
Kann man was verbessern oder muss man gar was ganz anders machen?
Thx @all
*edit code nochmal geändert
Zuletzt bearbeitet: