Ik ben PHP OOP aan het leren en ik vraag me af of dit het zo moet of dat ik het helemaal verkeerd doe.
Als ik het niet goed doe, zeg dan aub hoe ik het wel goed kan doen.
init.php
Codeblok (voorbeeld.php):
1
2
3
4
5
spl_autoload_register(function($class){
requireclasses/ . $class . .php;
})
?>
index.php
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
requireinit.php;
?>
$x = new formCheck();
$c = new formSend();
echo $x->check($_POST[textInput], $_POST[moreInput]);
?>
formcheck.php
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class formCheck{
public $textInput;
public $moreInput;
public function check($textInput, $moreInput){
if($_SERVER[REQUEST_METHOD] == POST){
if(empty($textInput)){
echoThe first textbox was empty.
;
}
if(empty($moreInput)){
echoThe second textbox was empty.;
}
else{
//Send code
}
}
}
}
?>
Als ik het niet goed doe, zeg dan aub hoe ik het wel goed kan doen.
init.php
Codeblok (voorbeeld.php):
1
2
3
4
5
spl_autoload_register(function($class){
requireclasses/ . $class . .php;
})
?>
index.php
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
requireinit.php;
?>
$x = new formCheck();
$c = new formSend();
echo $x->check($_POST[textInput], $_POST[moreInput]);
?>
formcheck.php
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class formCheck{
public $textInput;
public $moreInput;
public function check($textInput, $moreInput){
if($_SERVER[REQUEST_METHOD] == POST){
if(empty($textInput)){
echoThe first textbox was empty.
;
}
if(empty($moreInput)){
echoThe second textbox was empty.;
}
else{
//Send code
}
}
}
}
?>